当前使用版本(必须填写清楚,否则不予处理)
compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter', version: '3.3.0'
该问题是怎么引起的?(最新版上已修复的会直接close掉)
使用postgresql数据库,使用service.save保存一个对象,插入的key会变成true,代码在3.0.1上面是正常运行的的。
重现步骤
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class DevArea implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String name;
private String latlng;
private String remark;
}
// area:{"name":"xx"}
areaMapper.insert(area)
报错信息
org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "true"
Position: 23
### The error may exist in **/DevAreaMapper.java (best guess)
### The error may involve **mapper.DevAreaMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO dev_area (true, create_time, update_time, tenant_id) VALUES (?, ?, ?, 'test')
### Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "true"
Position: 23
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "true"
Position: 23
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235) ~[spring-jdbc-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88) ~[mybatis-spring-2.0.3.jar:2.0.3]
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) ~[mybatis-spring-2.0.3.jar:2.0.3]
at com.sun.proxy.$Proxy82.insert(Unknown Source) ~[na:na]
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271) ~[mybatis-spring-2.0.3.jar:2.0.3]
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:60) ~[mybatis-plus-core-3.3.0.jar:3.3.0]
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:96) ~[mybatis-plus-core-3.3.0.jar:3.3.0]
at com.sun.proxy.$Proxy83.insert(Unknown Source) ~[na:na]
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.save(ServiceImpl.java:114) ~[mybatis-plus-extension-3.3.0.jar:3.3.0]
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl$$FastClassBySpringCGLIB$$76535273.invoke(<generated>) ~[mybatis-plus-extension-3.3.0.jar:3.3.0]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:685) ~[spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
at xx.service.impl.AreaServiceImpl$$EnhancerBySpringCGLIB$$1d011cc.save(<generated>) ~[main/:na]
Comment From: miemieYaho
给出你的复现demo
Comment From: hcl04
Comment From: wumuwumu
DevArea
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class DevArea implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String name;
private Double baseArea;
private String latlng;
}
DevAreaMapper
public interface DevAreaMapper extends BaseMapper<DevArea> {
}
## DevAreaMapper.xml
```java
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sciento.mybatisplus.mybatisplusdemo.mapper.DevAreaMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.sciento.mybatisplus.mybatisplusdemo.entity.DevArea">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="base_area" property="baseArea" />
<result column="latlng" property="latlng" />
<result column="remark" property="remark" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, name, base_area, latlng, remark, tenant_id
</sql>
</mapper>
application.yaml
....
mybatis-plus:
mapper-locations: classpath:/mapper/*.xml
typeAliasesPackage: com.sciento.mybatisplus.mybatisplusdemo.entity
global-config:
db-config:
column-format: true
refresh-mapper: true
logic-delete-value: 1
logic-not-delete-value: 0
cache-enabled: false
id-type: AUTO
MybatisPlusConfig
@Configuration
@MapperScan("com.sciento.mybatisplus.mybatisplusdemo.mapper")
public class MybatisPlusConfig {
}
AreaService
public interface AreaService extends IService<DevArea> {
}
AreaServiceImpl
@Service
public class AreaServiceImpl extends ServiceImpl<DevAreaMapper, DevArea> implements AreaService {
@Autowired
private DevAreaMapper areaMapper;
@PostConstruct
public void post(){
DevArea area = new DevArea();
area.setName("1122221");
areaMapper.insert(area);
}
}
Comment From: hcl04
这字段怎么一个都没有对上?
Comment From: wumuwumu
xml是充其他工程复制过来的有些没有删除,统一也是一样的
Comment From: miemieYaho
不要整杂七杂八的,给一个能跑的git项目
Comment From: hcl04
ok,let us do it