sql
<insert id="save" parameterType="com.sifude.entity.SysRole" useGeneratedKeys="true" keyProperty="roleId" flushCache="true" >
insert into tbl_sys_role (role_id, name, description,
create_time, record_status)
values (null, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR},
CURRENT_TIMESTAMP, #{recordStatus,jdbcType=SMALLINT}
)
</insert>
spring-mybatis.xml
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-config.xml" />
<property name="mapperLocations" value="classpath:com/operation/mapper/*Mapper.xml" />
<property name="typeAliasesPackage" value="com.operation.entity" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name="basePackage" value="com.operation.dao"/>
</bean>
<bean id="batchSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
<!--更新采用批量模式 -->
<constructor-arg index="1" value="BATCH"/>
</bean>
应该怎么配置insert才能返回key?
采用了批量更新模式是不能返回主键的,改为普通更新模式就好了。如果用批量更新模式,就是用
spring-batch
来更新数据。