mybatis plus page eq 多个条件, com.baomidou.mybatisplus.extension.plugins.pagination.Page 好使,
import com.github.pagehelper.Page; 不好使
下面这个好使
@RequestMapping(value = "/selectPage/equal/byPage", method = RequestMethod.POST)
public Object selectPageEqualByPage(@RequestBody MultiQuestion multiQuestion,
@RequestParam(required = false, defaultValue = "0") int pageNumber,
@RequestParam(required = false, defaultValue = "10") int pageSize) {
try {
//创建一个page对象
// Page<MultiQuestion> pageTeacher = new Page<>();
com.baomidou.mybatisplus.extension.plugins.pagination.Page<MultiQuestion> pageTeacher =
new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNumber,pageSize);
// com.baomidou.mybatisplus.extension.plugins.pagination.Page
// PageHelper.startPage(pageNumber,pageSize);
LambdaQueryWrapper<MultiQuestion> equals = equalWrapper(multiQuestion);
// LambdaQueryWrapper<MultiQuestion> equals = equalWrapper2(multiQuestion);
log.info("equals {}",equals);
// log.info(equals.toString());
String sqlSelect = equals.getSqlSelect();
log.info("sqlSelect {}",sqlSelect);
// List<MultiQuestion> list = multiQuestionService.list(equals);
IPage<MultiQuestion> page = multiQuestionService.page(pageTeacher, equals);
// Page writersPage = (Page) list;
// log.info(" list {}",list);
return ReturnT.success(page);
}catch (Exception e){
log.info("error {}",e.getMessage());
// return ApiResultHandler.buildApiResult(ApiResultHandler.error,e.getMessage(),e.getMessage());
return ReturnT.error(e.getMessage());
}
// finally {
// PageHelper.clearPage();
// }
}
LambdaQueryWrapper<MultiQuestion> equalWrapper(MultiQuestion multiQuestion){
LambdaQueryWrapper<MultiQuestion> equals = Wrappers.lambdaQuery();
equals
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getQuestionId()),
MultiQuestion::getQuestionId,
multiQuestion.getQuestionId()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getSubject()),
MultiQuestion::getSubject,
multiQuestion.getSubject()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getQuestion()),
MultiQuestion::getQuestion,
multiQuestion.getQuestion()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerA()),
MultiQuestion::getAnswerA,
multiQuestion.getAnswerA()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerB()),
MultiQuestion::getAnswerB,
multiQuestion.getAnswerB()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerC()),
MultiQuestion::getAnswerC,
multiQuestion.getAnswerC()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerD()),
MultiQuestion::getAnswerD,
multiQuestion.getAnswerD()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getRightAnswer()),
MultiQuestion::getRightAnswer,
multiQuestion.getRightAnswer()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnalysis()),
MultiQuestion::getAnalysis,
multiQuestion.getAnalysis()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getScore()),
MultiQuestion::getScore,
multiQuestion.getScore()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getSection()),
MultiQuestion::getSection,
multiQuestion.getSection()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getLevel()),
MultiQuestion::getLevel,
multiQuestion.getLevel()
)
;
return equals;
}
pect : 开始执行 class com.exam.controller.Mult
iQuestionControllerMbp.selectPageEqualByPage
2022-07-16 14:39:13.019 INFO 44216 --- [nio-8082-exec-6] c.e.c.MultiQuestionControllerMbp : equals com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper@7b77f137
2022-07-16 14:39:13.019 INFO 44216 --- [nio-8082-exec-6] c.e.c.MultiQuestionControllerMbp : sqlSelect null
2022-07-16 14:39:13.020 DEBUG 44216 --- [nio-8082-exec-6] c.e.m.MultiQuestionMapper.selectPage : ==> Preparing: SELECT COUNT(1) FROM ( SELECT questionId,subject,section,answerA,answerB,answerC,answerD,question,level,rightAnswer,analysis,score FROM multi_question ) TOTAL
2022-07-16 14:39:13.021 DEBUG 44216 --- [nio-8082-exec-6] c.e.m.MultiQuestionMapper.selectPage : ==> Parameters:
2022-07-16 14:39:13.032 DEBUG 44216 --- [nio-8082-exec-6] c.e.m.MultiQuestionMapper.selectPage : ==> Preparing: SELECT questionId,subject,section,answerA,answerB,answerC,answerD,question,level,rightAnswer,analysis,score FROM multi_question LIMIT ?,?
2022-07-16 14:39:13.032 DEBUG 44216 --- [nio-8082-exec-6] c.e.m.MultiQuestionMapper.selectPage : ==> Parameters: 0(Long), 10(Long)
2022-07-16 14:39:13.044 DEBUG 44216 --- [nio-8082-exec-6] c.e.m.MultiQuestionMapper.selectPage : <== Total: 10
2022-07-16 14:39:13.045 INFO 44216 --- [nio-8082-exec-6] com.exam.config.ControllerAspect : 方法执行完毕, 共用时:26毫秒
github page不好使 PageHelper.startPage(pageNumber,pageSize);
/**
*
let data= {
"questionId":null ,
"subject":null ,
"question":null ,
"answerA":null ,
"answerB":null ,
"answerC":null ,
"answerD":null ,
"rightAnswer":null ,
"analysis":null ,
"score":null ,
"section":null ,
"level":null
}
axios.post(Common.baseUrl + `/multiQuestion/selectPage/equal?pageNumber=${this.pageNumber}&pageSize=${this.pageSize}`,data).then(res => {
console.log("res");
console.log(res);
});
*/
@RequestMapping(value = "/selectPage/equal", method = RequestMethod.POST)
public Object selectPageEqual(@RequestBody MultiQuestion multiQuestion,
@RequestParam(required = false, defaultValue = "0") int pageNumber,
@RequestParam(required = false, defaultValue = "10") int pageSize) {
try {
PageHelper.startPage(pageNumber,pageSize);
LambdaQueryWrapper<MultiQuestion> equals = Wrappers.lambdaQuery();
equals
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getQuestionId()),
MultiQuestion::getQuestionId,
multiQuestion.getQuestionId()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getSubject()),
MultiQuestion::getSubject,
multiQuestion.getSubject()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getQuestion()),
MultiQuestion::getQuestion,
multiQuestion.getQuestion()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerA()),
MultiQuestion::getAnswerA,
multiQuestion.getAnswerA()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerB()),
MultiQuestion::getAnswerB,
multiQuestion.getAnswerB()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerC()),
MultiQuestion::getAnswerC,
multiQuestion.getAnswerC()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerD()),
MultiQuestion::getAnswerD,
multiQuestion.getAnswerD()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getRightAnswer()),
MultiQuestion::getRightAnswer,
multiQuestion.getRightAnswer()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getAnalysis()),
MultiQuestion::getAnalysis,
multiQuestion.getAnalysis()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getScore()),
MultiQuestion::getScore,
multiQuestion.getScore()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getSection()),
MultiQuestion::getSection,
multiQuestion.getSection()
)
.eq(
!StringUtils.isNullOrEmpty(multiQuestion.getLevel()),
MultiQuestion::getLevel,
multiQuestion.getLevel()
)
;
log.info("equals {}",equals);
// log.info(equals.toString());
String sqlSelect = equals.getSqlSelect();
log.info("sqlSelect {}",sqlSelect);
List<MultiQuestion> list = multiQuestionService.list(equals);
Page writersPage = (Page) list;
log.info(" list {}",list);
return ReturnT.success(writersPage);
}catch (Exception e){
log.info("error {}",e.getMessage());
// return ApiResultHandler.buildApiResult(ApiResultHandler.error,e.getMessage(),e.getMessage());
return ReturnT.error(e.getMessage());
}
finally {
PageHelper.clearPage();
}
}
: 传入参数: [MultiQuestion(questionId=null, subject=null, section=null, answerA=null, answerB=null, answerC=null, answerD=null, question=null, level=null, rightAnswer=null, analysis=null, score=null), 0, 10]
2022-07-16 14:20:39.439 INFO 49776 --- [nio-8082-exec-2] com.exam.config.ControllerAspect : 开始执行 class com.exam.controller.MultiQuestionControllerMbp.selectPageEqual
2022-07-16 14:20:39.446 INFO 49776 --- [nio-8082-exec-2] c.e.c.MultiQuestionControllerMbp : equals com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper@4aab80f8
2022-07-16 14:20:39.446 INFO 49776 --- [nio-8082-exec-2] c.e.c.MultiQuestionControllerMbp : sqlSelect null
2022-07-16 14:20:39.484 DEBUG 49776 --- [nio-8082-exec-2] c.e.m.M.selectList_COUNT : ==> Preparing: SELECT count(0) FROM multi_question
2022-07-16 14:20:39.493 DEBUG 49776 --- [nio-8082-exec-2] c.e.m.M.selectList_COUNT : ==> Parameters:
2022-07-16 14:20:39.517 DEBUG 49776 --- [nio-8082-exec-2] c.e.m.M.selectList_COUNT : <== Total: 1
2022-07-16 14:20:39.517 INFO 49776 --- [nio-8082-exec-2] c.e.c.MultiQuestionControllerMbp : list Page{count=true, pageNum=0, pageSize=10, startRow=0, endRow=0, total=34, pages=4, reasonable=false, pageSizeZero=false}[]
2022-07-16 14:20:39.518 INFO 49776 --- [nio-8082-exec-2] com.exam.config.ControllerAspect : 方法执行完毕, 共用时:80毫秒
但是github page PageHelper.startPage(pageNumber,pageSize); like的多条件 他又是好使的
这里搞错了 其实也不行,估计是分页插件的问题,一个项目 只能用同一种分页插件吧
只能用同一种分页插件吧
@RequestMapping(value = "/selectPage", method = RequestMethod.POST)
public Object selectPage(@RequestBody MultiQuestion multiQuestion,
@RequestParam(required = false, defaultValue = "0") int pageNumber,
@RequestParam(required = false, defaultValue = "10") int pageSize) {
try {
// boolean save = multiQuestionService.save(multiQuestion);
List<MultiQuestion>multiQuestions=new ArrayList<>();
// multiQuestionService.saveOrUpdate(multiQuestions);
// multiQuestionService.saveOrUpdateBatch(multiQuestions);
mybatis.configuration.mapUnderscoreToCamelCase
// multiQuestionService.deleteBatch(multiQuestions);
// multiQuestionService.removeById()
// mapUnderscoreToCamelCase false
log.info("mapUnderscoreToCamelCase {}",mapUnderscoreToCamelCase);
log.info("selectPage");
PageHelper.startPage(pageNumber,pageSize);
LambdaQueryWrapper<MultiQuestion> like = Wrappers.lambdaQuery();
like .like(
!StringUtils.isNullOrEmpty(multiQuestion.getQuestionId()),
MultiQuestion::getQuestionId,
multiQuestion.getQuestionId()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getSubject()),
MultiQuestion::getSubject,
multiQuestion.getSubject()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getQuestion()),
MultiQuestion::getQuestion,
multiQuestion.getQuestion()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerA()),
MultiQuestion::getAnswerA,
multiQuestion.getAnswerA()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerB()),
MultiQuestion::getAnswerB,
multiQuestion.getAnswerB()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerC()),
MultiQuestion::getAnswerC,
multiQuestion.getAnswerC()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getAnswerD()),
MultiQuestion::getAnswerD,
multiQuestion.getAnswerD()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getRightAnswer()),
MultiQuestion::getRightAnswer,
multiQuestion.getRightAnswer()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getAnalysis()),
MultiQuestion::getAnalysis,
multiQuestion.getAnalysis()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getScore()),
MultiQuestion::getScore,
multiQuestion.getScore()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getSection()),
MultiQuestion::getSection,
multiQuestion.getSection()
)
.like(
!StringUtils.isNullOrEmpty(multiQuestion.getLevel()),
MultiQuestion::getLevel,
multiQuestion.getLevel()
)
;
List<MultiQuestion> list = multiQuestionService.list(like);
Page writersPage = (Page) list;
// return ApiResultHandler.buildApiResult(writersPage);
return ApiResultHandler.buildApiResult(200,"添加成功",writersPage);
}
catch (Exception e){
log.info("error {}",e.getMessage());
return ApiResultHandler.buildApiResult(ApiResultHandler.error,e.getMessage(),e.getMessage());
}
finally {
PageHelper.clearPage();
}
}