新世界英语springboot实体映射到数据库_【Java】数据库mapper与实体
字段对应,Spr。。。
SpringBoot开启驼峰映射
主要的属性设置
1,引⼊了mybatis-spring-boot-starter的项⽬,可以直接去配置参数
mybatis-spring-boot-starter
1.1.1
可以在l配置
mybatis:
configuration:
map-underscore-to-camel-ca: true
或者在spring boot项⽬中没有l⽂件,配置⽂件application.properties中,加⼊配置项:
#mybatis配置 #指定l的位置
mybatis.mapper-locations=classpath:mapper/*.xml
indemand2,⼿动通过javaBean的⽅式配置,配置SqlSessionFactory
@Configuration
marvelous什么意思
@EnableTransactionManagementostrava
// 开启注解事务⽀持
vso
public class MybatisConfig implements TransactionManagementConfigurer {
@Autowired
private DataSource dataSource;
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.tDataSource(dataSource);
bean.tTypeAliasPackage("del");
org.apache.ibatis.ssion.Configuration configuration=new org.apache.ibatis.ssion.Configuration();
configuration.tUGeneratedKeys(true);//使⽤jdbc的getGeneratedKeys获取数据库⾃增主键值
configuration.tUColumnLabel(true);//使⽤列别名替换列名 lect ur as Ur
configuration.tMapUnderscoreToCamelCa(true);//-⾃动使⽤驼峰命名属性映射字段 urId ur_id bean.tConfiguration(configuration);
bean.tFailFast(true);
Properties properties = new Properties();
properties.tProperty("helperDialect", "postgresql");
properties.tProperty("reasonable", "true");
properties.tProperty("supportMethodsArguments", "true");
properties.tProperty("params", "count=countSql");
// 分页插件
PageInterceptor pageInterceptor = new PageInterceptor();
pageInterceptor.tProperties(properties);
// 添加插件
LogSqlInterceptor logSqlInterceptor = new LogSqlInterceptor();
bean.tPlugins(new Interceptor[] { pageInterceptor, logSqlInterceptor });
// 添加XML⽬录
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Listresources = new ArrayList<>();
// 添加 多个路径
try {
resources.addAll(Arrays.Resources("classpath:mapper/**/*.xml")));
bean.Array(new Resource[resources.size()]));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
Object();
}
@Bean
public SqlSessionTemplate sqlSessionTemplate(就业最好的专业
SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
// 开启注解事务
2006年时代周刊风云人物@Bean
farrah fawcett
skyscraper@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
return new DataSourceTransactionManager(dataSource);
成人高考语文}
}
最后对于l的配置可以 如下:1直接对应实体类;2不配置⾃动驼峰映射就⾃⼰写resultMap的映射resultType="del.fm.InvoiceModel">