Closed CarlJia closed 6 years ago
配置 settings 中 的 jdbcTypeForNull
试试。
@abel533 这个加过了,现在改成
mapper:
mappers:
- tk.mybatis.mapper.common.Mapper
not-empty: false
identity: SYBASE
before: true
报错
按照sybase要求,你可能需要把 id 的 insertable=false
这样是可以的,但是回写 id 就不知道如何弄了,我主要想是插入主表和子表,根据主键关联,这样的操作
@CarlJia 你直接 getId 得不到回写的值吗?
@abel533 getId 是 null
@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelAndView save(Country country) {
ModelAndView result = new ModelAndView("view");
String msg = country.getId() == null ? "新增成功!" : "更新成功!";
countryService.save(country);
System.out.println("id="+country.getId());
result.addObject("country", country);
result.addObject("msg", msg);
return result;
}
配置
# mybatis \u914D\u7F6E
mybatis.type-aliases-package=tk.mybatis.springboot.model
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.configuration.jdbc-type-for-null=null
# \u901A\u7528 Mapper \u914D\u7F6E
mapper.mappers=tk.mybatis.springboot.util.MyMapper
mapper.not-empty=false
mapper.identity=select @@IDENTITY
mapper.before=true
2018-01-08 09:28:59.813 DEBUG 58332 --- [nio-9090-exec-9] o.m.s.t.SpringManagedTransaction : JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@1213d742] will not be managed by Spring 2018-01-08 09:28:59.814 DEBUG 58332 --- [nio-9090-exec-9] t.m.s.mapper.CountryMapper.insert : ==> Preparing: INSERT INTO country ( countryname,countrycode ) VALUES( ?,? ) 2018-01-08 09:28:59.815 DEBUG 58332 --- [nio-9090-exec-9] t.m.s.mapper.CountryMapper.insert : ==> Parameters: test(String), tts(String) 2018-01-08 09:28:59.831 DEBUG 58332 --- [nio-9090-exec-9] t.m.s.mapper.CountryMapper.insert : <== Updates: 1 2018-01-08 09:28:59.832 DEBUG 58332 --- [nio-9090-exec-9] org.mybatis.spring.SqlSessionUtils : Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4cb13f4a] 2018-01-08 09:28:59.832 DEBUG 58332 --- [nio-9090-exec-9] o.s.jdbc.datasource.DataSourceUtils : Returning JDBC Connection to DataSource
是自增的吧?
把 mapper.before=true 改成 false.
before false 后 id 也回写不了 唉,不搞了,让他们装个 MySQL 数据库了,这个 Sybase 真的是反人类啊,怎么诞生出来的。。。
c.t.r.mapper.OrderMergeMapper.insert : ==> Preparing: INSERT INTO plugin_order_merge ( id ) VALUES( ? )
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='id', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: JDBC requires that the JdbcType must be specified for all nullable parameters.
配置如下: mapper: mappers:
tk.mybatis.mapper.common.Mapper not-empty: false identity: SYBASE 实体类: @Data @MappedSuperclass public abstract class BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id;
@Transient private Integer page = 1;
@Transient private Integer rows = 10;
public boolean isNew() { return id == null; } }