后台访问代码:
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后面多了一个;
去掉;后报错解决。