首页 > 编程知识 正文

springboot事务,disruptor框架

时间:2023-05-05 04:49:30 阅读:171063 作者:4066

个人资料网站的链接

JOOQ是持久层的框架,主要特征如下。

逆向工程,自动根据数据库结构生成对应的类流API,并提供安全的SQL查询,以编写SQL。 JOOQ的主要优点是在编写SQL时进行检查,有助于支持几乎所有的DDL。 DML可以在内部避免SQL注入的安全问题,使用SQL呈现、打印和绑定,可以支持大部分非常轻、灵活、通过JPA简单的查询。 用JOOQ编写的复杂内容只能用JOOQ作为SQL执行器,只能用于生成SQL语句。 (类型安全)仅可用于处理SQL执行结果,Flyway、JAX-RS、JavaFX、Kotlin、Nashorn、Scala、Groovy和NoSQL为XML、 支持CSV。html导入导出多为事物提供支持的回滚Springboot JOOQ首次体验持久层框架,在此能否通过Springboot快速构建简单的demo以方便使用

配置为POM.xmldependencygroupidorg.spring framework.boot/groupidartifactidspring-boot-starter-jooq/artifact id/依赖的ependencybuildpluginspluginsplugingroupidorg.spring framework.boot/groupidartifactidspring-boot-maven-plugin/artifact id groupidartifactidjooq-codegen-maven/artifactidexecutionsexecutiongoalsgenerate/goal/goals/execution/executionsdependenciesdependencygroupidmysql/groupidartifactidmysql-connector-Java/artifactidversion5.1. 45/version ---配置文件--- -配置文件/main/resources/library.XML/configurationfilegeneratorgeners generator/configuration/plugin/plugins/build application.properties # datasourcespring.data source.URL llocalhost 3333333 demo spring.data source.username=root spring.data source.password=123456 spring.data source.driver-class-name=网上的JOOQ教程很少,很旧,建议你去官网复制对应版本的配置文件,并进行相应的修改。 不这样做的话,就无法生成。

? XML version=' 1.0 ' encoding=' utf-8 ' standalone=' yes '? configuration xmlns=' http://www.jooq.org/xsd/jooq-codegen-3.12.0.xsd '! - configurethedatabaseconnectionhere

--> <jdbc> <driver>com.mysql.cj.jdbc.Driver</driver> <url>jdbc:mysql://localhost:3306/demo</url> <user>root</user> <password>123456</password> </jdbc> <generator> <!-- The default code generator. You can override this one, to generate your own code style.Supported generators:- org.jooq.codegen.JavaGenerator-org.jooq.codegen.ScalaGenerator Defaults to org.jooq.codegen.JavaGenerator --> <name>org.jooq.codegen.JavaGenerator</name> <database> <!-- The database type. The format here is: org.jooq.meta.[database].[database]Database --> <name>org.jooq.meta.mysql.MySQLDatabase</name> <!-- The database schema (or in the absence of schema support, in your RDBMS this can be the owner, user, database name) to be generated --> <inputSchema>demo</inputSchema> <!-- All elements that are generated from your schema (A Java regular expression. Use the pipe to separate several expressions) Watch out for case-sensitivity. Depending on your database, this might be important! --> <includes>.*</includes> <!-- All elements that are excluded from your schema (A Java regular expression. Use the pipe to separate several expressions). Excludes match before includes, i.e. excludes have a higher priority --> <excludes></excludes> </database> <target> <!-- The destination package of your generated classes (within the destination directory) --> <packageName>com.example.springbootjooq.generated</packageName> <!-- The destination directory of your generated classes. Using Maven directory layout here --> <directory>src/main/java</directory> </target> </generator></configuration> 自动生成 我们在mysql中创建demo库,并创建一张User表如下(点的比较快,年龄字段用的varchar勿喷)mysql> describe user;+-------+-------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+-------------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || name | varchar(45) | NO | | NULL | || age | varchar(45) | NO | | NULL | |+-------+-------------+------+-----+---------+----------------+3 rows in set (0.00 sec) 执行compile,会把表结构的抽象,以及表对应的pojo自动生成到指定目录,然后就可以愉快的coding了mvn clean compile Demo

这里实现了最基本的功能

Controller @RestController@RequestMapping("/demo/")public class DemoController { @Autowired private DemoService service; @RequestMapping("/insert/user/{name}/{age}") public void insert(@PathVariable String age, @PathVariable String name){ service.insert(new User().setAge(age).setName(name)); } @RequestMapping("/update/user/{name}/{age}") public void update(@PathVariable String age, @PathVariable String name){ service.update(new User().setAge(age).setName(name)); } @RequestMapping("/delete/user/{id}") public void delete(@PathVariable Integer id){ service.delete(id); } @RequestMapping("/select/user/{id}") public User selectByID(@PathVariable Integer id){ return service.selectById(id); } @RequestMapping("/select/user/") public List<User> selectByID(){ return service.selectAll(); }} Service @Servicepublic class DemoServiceImpl implements DemoService { @Autowired DSLContext create; com.example.springbootjooq.generated.tables.User USER = com.example.springbootjooq.generated.tables.User.USER; @Override public void delete(int id) { create.delete(USER).where(USER.ID.eq(id)).execute(); } @Override public void insert(User user) { create.insertInto(USER) .columns(USER.NAME,USER.AGE) .values(user.getName(), user.getAge()) .execute(); } @Override public int update(User user) { create.update(USER).set((Record) user); return 0; } @Override public User selectById(int id) { return create.select(USER.NAME,USER.AGE).from(USER).where(USER.ID.eq(id)).fetchInto(User.class).get(0); } @Override public List<User> selectAll() { return create.select().from(USER).fetchInto(User.class); }}

Demo源码地址

参考

https://blog.csdn.net/weixin_40826349/article/details/89887355

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。