Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use springboot beatlsql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use springboot beatlsql". In daily operation, I believe many people have doubts about how to use springboot beatlsql. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use springboot beatlsql". Next, please follow the editor to study!

BeetSql is a full-function DAO tool, which also has the advantages of Hibernate & Mybatis. It is suitable for applications that recognize SQL as the center and require tools to automatically generate a large number of commonly used SQL.

Advantages of beatlsql

Development efficiency

Do not need comments, automatically use a large number of built-in SQL, easily complete the addition, deletion, modification and query function, and save 50% of the development workload

The data model supports Pojo, a fast model such as Map/List, and a mixed model SQL template based on Beetl, which makes it easier to write and debug, and extends maintainability.

You can automatically map sql files to dao interface classes

Flexible and intuitive support for one-to-one, one-to-many, many-to-many relationship mapping without introducing complex OR Mapping concepts and technologies.

With Interceptor function, can debug, performance diagnosis SQL, and expand other functions other built-in support for master-slave database support open source tools to support cross-database platform, developers need to reduce the work to a minimum, currently cross-database support mysql,postgres,oracle,sqlserver,h3,sqllite,DB2.

Introduce dependency

Org.springframework.boot spring-boot-devtools true com.ibeetl beetl 2.3.2 com.ibeetl beetlsql 2.3.1 mysql mysql-connector-java 5.0.5

Integration stage

Since springboot does not have a quick start assembly of beatlsql, I need to import the relevant bean myself, including data sources, package scanning, transaction manager, etc.

Add the following code to application:

@ Bean (initMethod = "init", name = "beetlConfig") public BeetlGroupUtilConfiguration getBeetlGroupUtilConfiguration () {BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration (); ResourcePatternResolver patternResolver = ResourcePatternUtils.getResourcePatternResolver (new DefaultResourceLoader ()); try {/ / WebAppResourceLoader configuration root path is the key WebAppResourceLoader webAppResourceLoader = new WebAppResourceLoader (patternResolver.getResource ("classpath:/templates"). GetFile (). GetPath (); beetlGroupUtilConfiguration.setResourceLoader (webAppResourceLoader) } catch (IOException e) {e.printStackTrace ();} / / read profile information 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;} / / configure package scanning @ Bean (name = "beetlSqlScannerConfigurer") public BeetlSqlScannerConfigurer getBeetlSqlScannerConfigurer () {BeetlSqlScannerConfigurer conf = new BeetlSqlScannerConfigurer (); conf.setBasePackage ("com.forezp.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 UnderlinedNameConversion ()) / / enable hump factory.setSqlLoader (new ClasspathLoader ("/ sql")); / / sql file path return factory;} / / configuration database @ Bean (name = "datasource") public DataSource getDataSource () {return DataSourceBuilder.create (). Url ("jdbc:mysql://127.0.0.1:3306/test"). Username ("root"). Password ("123456"). Build () } / / Open transaction @ Bean (name = "txManager") public DataSourceTransactionManager getDataSourceTransactionManager (@ Qualifier ("datasource") DataSource datasource) {DataSourceTransactionManager dsm = new DataSourceTransactionManager (); dsm.setDataSource (datasource); return dsm;}

Under the resouces package, add the META_INF folder, and add spring-devtools.properties to the folder:

Restart.include.beetl=/beetl-2.3.2.jarrestart.include.beetlsql=/beetlsql-2.3.1.jar

With the addition of the bean of jar and the configuration of beatlsql, and the configuration of resources, springboot can access database classes.

Take restful's chestnut.

Initialize the table of the database

# DROP TABLE `roomt` IF EXISTSCREATE TABLE `roomt` (`id`int (11) NOT NULL AUTO_INCREMENT, `name` varchar (20) NOT NULL, `money`double DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;INSERT INTO `roomt`VALUES ('1million,' aaa', '1000'); INSERT INTO `roomt`VALUES (' 2percent, 'bbb',' 1000'); INSERT INTO `roomt`VALUES ('3percent,' ccc', '1000')

Bean

Public class Account {private int id; private String name; private double money; getter... Setter... At this point, the study on "how to use springboot beatlsql" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report