springboot+beetlsql+mysql整合

Easter79
• 阅读 623

一、工程目录结构

 springboot+beetlsql+mysql整合

二、pom.xml文件配置

<dependency>   <groupId>mysql</groupId>   <artifactId>mysql-connector-java</artifactId>   <scope>runtime</scope></dependency>      <!--beetlsql-->      <dependency>          <groupId>com.ibeetl</groupId>          <artifactId>beetl-framework-starter</artifactId>          <version>1.1.35.RELEASE</version>      </dependency>      <dependency>          <groupId>com.ibeetl</groupId>          <artifactId>beetlsql</artifactId>          <version>2.10.10</version>      </dependency>

三、beetlsqlConfig文件

@Configurationpublic class BeetlSqlConfig {  //=============以下是beetl配置=========================    @Bean(initMethod = "init", name = "beetlConfig")    public BeetlGroupUtilConfiguration getBeetlGroupUtilConfiguration() {        BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration();        ResourcePatternResolver patternResolver = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader());        // WebAppResourceLoader 配置root路径是关键        //WebAppResourceLoader webAppResourceLoader = new WebAppResourceLoader(patternResolver.getResource("classpath:/sql").getFile().getPath());        WebAppResourceLoader webAppResourceLoader = new WebAppResourceLoader();        beetlGroupUtilConfiguration.setResourceLoader(webAppResourceLoader);        //读取配置文件信息        return beetlGroupUtilConfiguration;    }    @Bean(name = "beetlViewResolver")    public BeetlSpringViewResolver getBeetlSpringViewResolver(@Qualifier("beetlConfig") BeetlGroupUtilConfiguration beetlGroupUtilConfiguration) {        BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();        beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");        beetlSpringViewResolver.setOrder(0);        beetlSpringViewResolver.setConfig(beetlGroupUtilConfiguration);        return beetlSpringViewResolver;    }//=============================以下是beetsql配置=============    //配置包扫描    @Bean(name = "beetlSqlScannerConfigurer")    public BeetlSqlScannerConfigurer getBeetlSqlScannerConfigurer() {        BeetlSqlScannerConfigurer conf = new BeetlSqlScannerConfigurer();        conf.setBasePackage(" com.example.demo.dao");        conf.setDaoSuffix("Dao");        conf.setSqlManagerFactoryBeanName("sqlManagerFactoryBean");        return conf;    }    @Bean(name = "sqlManagerFactoryBean")    @Primary    public SqlManagerFactoryBean getSqlManagerFactoryBean(@Qualifier("datasource") DataSource datasource) {        SqlManagerFactoryBean factory = new SqlManagerFactoryBean();        BeetlSqlDataSource source = new BeetlSqlDataSource();        source.setMasterSource(datasource);        factory.setCs(source);        factory.setDbStyle(new MySqlStyle());        factory.setInterceptors(new Interceptor[]{new DebugInterceptor()});        factory.setNc(new DefaultNameConversion());        factory.setSqlLoader(new ClasspathLoader("/sql"));        //sql文件路径        return factory;    }    //配置数据库    @Bean(name = "datasource")    public DataSource getDataSource(Environment env) {        String url = env.getProperty("spring.datasource.mysql.url");        String userName = env.getProperty("spring.datasource.mysql.username");        String password = env.getProperty("spring.datasource.mysql.password");        return DataSourceBuilder.create().url(url).username(userName).password(password).build();    }    //开启事务    @Bean(name = "transactionManager")    public DataSourceTransactionManager getDataSourceTransactionManager(@Qualifier("datasource") DataSource datasource) {        DataSourceTransactionManager dsm = new DataSourceTransactionManager();        dsm.setDataSource(datasource);        return dsm;    }}

四、dao层,继承一个BaseMapper

springboot+beetlsql+mysql整合

五、service层

springboot+beetlsql+mysql整合

点赞
收藏
评论区
推荐文章
kenx kenx
3年前
个人博客开发之blog-api项目整合MyBatisPlus代码自动生成CURD
整合MybatisPlus导入依赖xml<!mysql<dependency<groupIdmysql</groupId<artifactIdmysqlconnectorjava</artifactId<scoperuntime</scope
待兔 待兔
3个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Easter79 Easter79
3年前
spring使用jetty+jndi配置druid数据源
maven项目pom.xml配置1、配置druid的jar依赖:<dependency<groupIdcom.alibaba</groupId<artifactIddruid</artifac
Wesley13 Wesley13
3年前
java+selenium+maven+IntelliJ IDEA 搭建简单的UI自动化测试环境
1\.用IntelliJIDEA新建一个maven工程2\.在pom.xml中添加依赖:<dependency<groupIdorg.seleniumhq.selenium</groupId<artifactIdseleniumjava</artifactId
Easter79 Easter79
3年前
springBoot配置druid数据源
1.pom.xml<dependency<groupIdmysql</groupId<artifactIdmysqlconnectorjava</artifactId</dependency<dependency<groupIdcom.alibaba</groupId<artifactIddru
Stella981 Stella981
3年前
Android So动态加载 优雅实现与原理分析
背景:漫品Android客户端集成适配转换功能(基于目标识别(So库35M)和人脸识别库(5M)),导致apk体积50M左右,为优化客户端体验,决定实现So文件动态加载.!(https://oscimg.oschina.net/oscnet/00d1ff90e4b34869664fef59e3ec3fdd20b.png)点击上方“蓝字”关注我
Easter79 Easter79
3年前
SpringBoot配置Swagger实例(POST接收json参数)
工程目录结构:!(https://oscimg.oschina.net/oscnet/207b6df22d35c70fd7ef5ba084e9e0eff60.png)首先,引入jar包,只需要以下两个即可<dependency<groupIdio.springfox</groupId<
Stella981 Stella981
3年前
SpringBoot配置Swagger实例(POST接收json参数)
工程目录结构:!(https://oscimg.oschina.net/oscnet/207b6df22d35c70fd7ef5ba084e9e0eff60.png)首先,引入jar包,只需要以下两个即可<dependency<groupIdio.springfox</groupId<
Stella981 Stella981
3年前
IDEA+SpringBoot+Mybatis Generator+MySQL8.0.17自动生成实体类和Mapper
1、搭建SpringBoot项目2、修改pom.xml文件添加依赖:!(https://oscimg.oschina.net/oscnet/15023a0b19569ea825b5255db0d44d1a651.png)<dependency<groupIdmysql</groupId<artifactIdmysq
Stella981 Stella981
3年前
SpringBoot2.0 配置Log4j2记录日志
pom.xml配置<dependency<groupIdorg.springframework.boot</groupId<artifactIdspringbootstarter</artifactId<exclusions
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k