### The error may involve defaultParameterMap ### The error occurred while setting parameters

时间:2022-03-05 07:14:57

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Query was empty
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Query was empty]

今天用mybatis+pageHelp时发生这个错误,原因是:

错误代码:

    public PageInfo<Log> getLogPage(Integer pageNum) {
//设置每页显示数量
int pageSize = 5;
PageHelper.startPage(pageNum, pageSize);
//执行分页查询
NMRoutingToken token = new NMRoutingToken("LOG_DATA_SOURCE_KEY");
List<String> tableNameList = logMapper.selectAlltableName(); NMRoutingToken token1 = new NMRoutingToken("LOG_DATA_SOURCE_KEY"); List<Log> logList=logMapper.selectAllLog(tableNameList);
//对获取的数据进行包装
int navigatePages = 6;
PageInfo<Log> page = new PageInfo<>(logList, navigatePages);
return page;
}

正确:

    public PageInfo<Log> getLogPage(Integer pageNum) {

        //执行分页查询
NMRoutingToken token = new NMRoutingToken("LOG_DATA_SOURCE_KEY");
List<String> tableNameList = logMapper.selectAlltableName(); NMRoutingToken token1 = new NMRoutingToken("LOG_DATA_SOURCE_KEY");
//设置每页显示数量
int pageSize = 5;
PageHelper.startPage(pageNum, pageSize);
List<Log> logList=logMapper.selectAllLog(tableNameList);
//对获取的数据进行包装
int navigatePages = 6;
PageInfo<Log> page = new PageInfo<>(logList, navigatePages);
return page;
}

pageHelp的页面设置应该在指定的sql前