<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
optionz注解将自增后得到的主键的值映射到javabean中
@Options(useGeneratedKeys = true,keyProperty = "id")
@Insert("insert into teacher(name,age) values(#{teacherName},#{age})")
int insertTeacher(Teacher teacher);
配置表的列名字和javabean中支持驼峰式映射
参考 MybatisAutoConfiguration
@Configuration
public class MybatisConfig {
@Bean
public ConfigurationCustomizer config(){
return (org.apache.ibatis.session.Configuration configuration)->{
configuration.setMapUnderscoreToCamelCase(true);
};
}
}