原代码:
QueryWrapper<entity> queryWrapper = QueryGenerator.initQueryWrapper(entity, null);
listQueryWrapperFun(req,queryWrapper);
private void listQueryWrapperFun(HttpServletRequest req,QueryWrapper<entity> initQueryWrapper){
String time = req.getParameter("time");
initQwrapper(initQueryWrapper,time)
}
接下来使用listQueryWrapperFun()方法对前端接收的数据进行拼接给到initQwrapper()方法进行条件查询组装
private void initQwrapper(QueryWrapper<entity>) initQueryWrapper,String time){
//判空
if(StringUtils.isNotBlank(time)) {
initQueryWrapper.eq("time", time);
}
}
数据库执行的sql为:
select * from 表名 where time = ? and time = ?
解决写法:直接实例化QueryWrapper
QueryWrapper<entity> queryWrapper = new QueryWrapper<>();
或者在实体类中把time属性设为null
entity.setTime(null);
QueryWrapper<entity> queryWrapper = QueryGenerator.initQueryWrapper(entity, null);
listQueryWrapperFun(req,queryWrapper);
private void listQueryWrapperFun(HttpServletRequest req,QueryWrapper<entity> initQueryWrapper){
String time = req.getParameter("time");
initQwrapper(initQueryWrapper,time)
}