关于在使用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;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王海林
 * @since 2021-09-07
 */
@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<Administrators> wrapper = Wrappers.<Administrators>lambdaQuery();

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


        Page<Administrators> 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后面多了一个;

去掉;后报错解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三横同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值