栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

关于在使用Mybatis-plus的分页插件与逻辑删除时,出现的sql错误

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

关于在使用Mybatis-plus的分页插件与逻辑删除时,出现的sql错误

后台访问代码:

package com.wang.mem.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.mem.common.Result;
import com.wang.mem.entity.Administrators;
import com.wang.mem.mapper.AdministratorsMapper;
import com.wang.mem.service.AdministratorsService;
import com.wang.mem.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@ResponseBody
public class AdministratorsController{
    @Autowired
    private AdministratorsService administratorsService;

    //通过引入 mapper层来直接使用 mybatis-plus自带的 分页插件
    @Resource
    private AdministratorsMapper administratorsMapper;

    @Autowired
    private EmployeeService employeeService;


    @PostMapping("/admin/add")
    public Result add(@RequestBody Administrators administrators){
        administratorsService.addAdministratorsLogon(administrators.getAdminId(),
                administrators.getPwd(),administrators.getName(),administrators.getSex(),
                administrators.getBirthplace(),administrators.getBirthTime(),
                administrators.getPhoneNumber(),administrators.getPhoneNumber());
        return Result.success();
    }


    @GetMapping("/admin/query")
    public Result findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search){


        LambdaQueryWrapper wrapper = Wrappers.lambdaQuery();

        if (StrUtil.isNotBlank(search)){
            wrapper.like(Administrators::getName, search);
        }


        Page administratorsPage = administratorsMapper.selectPage(new Page<>(pageNum, pageSize),wrapper);

        return Result.success(administratorsPage);
    }
}


访问结果:

后台日志报错信息:

==>  Preparing: SELECT COUNT(1) FROM administrators WHERe deleted = 0
==> Parameters: 
<==    Columns: COUNT(1)
<==        Row: 2
<==      Total: 1
==>  Preparing: SELECT adminId,pwd,name,sex,birthplace,birthTime,phoneNumber,Realm,perms,version,deleted,gmt_create,gmt_modified FROM administrators WHERe deleted=0; LIMIT ?
==> Parameters: 10(Long)
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@744dd865]
2021-10-05 12:16:28.966 ERROR 16844 --- [nio-9090-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 10' at line 1
### The error may exist in com/wang/mem/mapper/AdministratorsMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT  adminId,pwd,name,sex,birthplace,birthTime,phoneNumber,Realm,perms,version,deleted,gmt_create,gmt_modified  FROM administrators   WHERe  deleted=0; LIMIT ?
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 10' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 10' at line 1] with root cause

错误分析:SELECT adminId,pwd,name,sex,birthplace,birthTime,phoneNumber,Realm,perms,version,deleted,gmt_create,gmt_modified FROM administrators WHERe deleted=0; LIMIT ?多出了一个;导致报错

问题查找:

#???
#配置逻辑删除 删除1  为删除0 flag需要逻辑删除的字段
mybatis-plus.global-config.db-config.logic-delete-field=deleted
mybatis-plus.global-config.db-config.logic-delete-value=1;
mybatis-plus.global-config.db-config.logic-not-delete-value=0;

原因为 我的1和0后面多了一个;

去掉;后报错解决。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/295439.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号