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文件
@Configuration
public 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
五、service层
springboot+beetlsql+mysql整合的更多相关文章
- springboot+jpa+mysql+redis+swagger整合步骤
springboot+jpa+MySQL+swagger框架搭建好之上再整合redis: 在电脑上先安装redis: 一.在pom.xml中引入redis 二.在application.yml里配置r ...
- springboot+jpa+mysql+swagger整合
Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency> < ...
- 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程
工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...
- canal整合springboot实现mysql数据实时同步到redis
业务场景: 项目里需要频繁的查询mysql导致mysql的压力太大,此时考虑从内存型数据库redis里查询,但是管理平台里会较为频繁的修改增加mysql里的数据 问题来了: 如何才能保证mysql的数 ...
- springboot+mybatis+springmvc整合实例
以往的ssm框架整合通常有两种形式,一种是xml形式,一种是注解形式,不管是xml还是注解,基本都会有一大堆xml标签配置,其中有很多重复性的.springboot带给我们的恰恰是“零配置”,&quo ...
- SpringBoot+MyBatis+Mysql 详细示例
SpringBoot与MyBatis整合,底层数据库为mysql的使用示例 项目下载链接:https://github.com/DFX339/bootdemo.git 新建maven项目,web ...
- 30分钟带你了解Springboot与Mybatis整合最佳实践
前言:Springboot怎么使用想必也无需我多言,Mybitas作为实用性极强的ORM框架也深受广大开发人员喜爱,有关如何整合它们的文章在网络上随处可见.但是今天我会从实战的角度出发,谈谈我对二者结 ...
- springboot + mybatis +easyUI整合案例
概述 springboot推荐使用的是JPA,但是因为JPA比较复杂,如果业务场景复杂,例如企业应用中的统计等需求,使用JPA不如mybatis理想,原始sql调优会比较简单方便,所以我们的项目中还是 ...
- 在 springboot 中如何整合 shiro 应用 ?
Shiro是Apache下的一个开源项目,我们称之为Apache Shiro. 它是一个很易用与Java项目的的安全框架,提供了认证.授权.加密.会话管理,与spring Security 一样都是 ...
随机推荐
- 题目1413:神秘元素 ——lis的元素是否唯一
求序列的最长子序列中不可分割元素的数目.不可分割元素,肯定属于某一个最长子序列,首先做的就是把属于最长子序列的数提取出来,减小查找范围.怎么提取?可以用LIS(最长递增子序列)和LDS(最长递减子序列 ...
- docker怎么破?
为什么要装docker? 因为linux服务器不好用,很多操作不好进行,比如安装包没有管理员权限 docker可以访问本地显卡,比一般的virtual box 或者VMware都要好 怎么装docke ...
- Unit02: JDBC核心API
Unit02: JDBC核心API db.properties 注意:如果使用连接池,可以在这个文件中增加对连接池的相关设置: 连接池参数,常用参数有: 初始连接数 最大连接数 最小连接数 每次增加的 ...
- HDOJ5521(巧妙构建完全图)
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- postman 设置代理
点击右上角 图标(亮着的为录制中) 设置端口 和存放位置 把浏览器设置代理 localhost 8080 即可 filter中可以通过正则表达式来匹配自己关心的url 2018.9 后记: 今 ...
- python中scipy学习——随机稀疏矩阵及操作
1.生成随机稀疏矩阵: scipy中生成随机稀疏矩阵的函数如下: scipy.sparse.rand(m,n,density,format,dtype,random_state) 1 参数介绍: 参数 ...
- line 1: syntax error: unexpected word (expecting ")")
编译出来的程序在arm平台上运行时,出现下面的错误. / # wpa_supplicant -B -c/etc/wpa_wpa2.conf -iwlan0 /bin/wpa_supplicant: ...
- 【BZOJ】1001: [BeiJing2006]狼抓兔子(最小割 / 对偶图)
题目 传送门:QWQ 分析 显然答案是最小割. 然后dinic卡一卡过去了. 其实是懒得写转对偶图:正解 (dinic原来写的是vector,后来改的比较鬼畜 代码 #include <bits ...
- 打开图片并显示在面板上demo
import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ...
- Java四舍五入 保留小数
java 四舍五入保留小数 // 方式一: double f = 3.1516; BigDecimal b = new BigDecimal(f); double f1 = b.setScale( ...