Open kojz opened 6 years ago
看这里配置:https://github.com/abel533/Mapper/wiki/2.3-generatedvalue
另外。。。SELECT LAST_INSERT_ID() LIMIT ?
这里有 limit,说明你用错分页插件了。
你可能在 insert 前调用了一个分页方法。
我仔细检查了,在insert前,没有做pagehelper的操作,比较奇怪的是:这个bug是偶尔出现,有时insert又没错。我使用的版本如下:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.1</version>
</dependency>
参数配置是:
**
Mybatis & Mapper & PageHelper 配置 */ @Configuration public class MybatisConfigurer {
@Bean public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
factory.setDataSource(dataSource);
factory.setTypeAliasesPackage(ProjectConstant.MODEL_PACKAGE);
//添加XML目录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
Properties properties = new Properties();
//分页尺寸为0时查询所有纪录不再执行分页
properties.setProperty("pageSizeZero", "true");
//页码<=0 查询第一页,页码>=总页数查询最后一页
properties.setProperty("reasonable", "true");
//支持通过 Mapper 接口参数来传递分页参数
properties.setProperty("supportMethodsArguments", "true");
//配置分页插件,详情请查阅官方文档
Interceptor pageInterceptor = new PageInterceptor();
pageInterceptor.setProperties(properties);
SqlSessionFactory sqlSessionFactory = factory.getObject();
return sqlSessionFactory;
}
@Bean public MapperScannerConfigurer mapperScannerConfigurer() { MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean"); mapperScannerConfigurer.setBasePackage(ProjectConstant.MAPPER_PACKAGE);
//配置通用Mapper,详情请查阅官方文档
Properties properties = new Properties();
properties.setProperty("mappers", ProjectConstant.MAPPER_INTERFACE_REFERENCE);
//insert、update是否判断字符串类型!='' 即 test="str != null"表达式内是否追加 and str != ''
properties.setProperty("notEmpty", "false");
properties.setProperty("IDENTITY", "MYSQL");
mapperScannerConfigurer.setProperties(properties);
return mapperScannerConfigurer;
}
}
试试 supportMethodsArguments=false
最后怎么解决的啊,我也遇到这个问题了
PageHelper.clearPage(); 清空
问题解决了吗?我也碰到了
数据库表注解如下 :
id
int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',在调用mapper新增方法后,偶尔会出现如下错误(机率挺高的,偶尔又能新增成功,很奇怪),日志如下:
SELECT LAST_INSERT_ID() LIMIT ? Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml] SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana] Error selecting key or setting result to parameter object. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '?' at line 1