In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces Java Fluent Mybatis how to build the project and achieve code generation, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Characteristics
Take a look at the official feature diagram.
At first glance, it is very comprehensive to give several features, among which two are more attractive to me.
1. The syntax given in the figure is very similar to sql. If you don't take a closer look at it, you still think that it is a direct sql statement thrown up. It looks more practical.
2. No xml&mapper, although mybatis-plus has achieved a practical IService interface to implement most of the sql operations
Project building
The process of building a project by springboot does not go into much detail. Here is my practical version of springboot.
Org.springframework.boot spring-boot-starter-parent 2.5.5
The code structure is as follows:
Maven dependency introduction-fluent-mybatis 1.8.7 com.github.atool fluent-mybatis ${fluent-mybatis.version} com.github.atool fluent-mybatis-processor provided ${fluent-mybatis.version}
The complete maven depends on the following
4.0.0 org.springframework.boot spring-boot-starter-parent 2.5.5 com.hy fluent-mybatis-project 0.0.1-SNAPSHOT fluent-mybatis-project Demo project for Spring Boot 1.8 1.8.7 org.springframework.boot spring-boot-starter-web Org.springframework.boot spring-boot-devtools runtime true org.springframework.boot spring-boot-configuration-processor true org.projectlombok lombok true org.springframework.boot Spring-boot-starter-test test org jaudiotagger 2.0.1 com.google.guava guava 30.1.1-jre cn.hutool hutool-all 5.5.2 Com.github.atool fluent-mybatis ${fluent-mybatis.version} com.github.atool fluent-mybatis-processor provided ${fluent-mybatis.version} org.mybatis.spring.boot mybatis- Spring-boot-starter 2.2.0 mysql mysql-connector-java runtime org.springframework.boot spring-boot-maven-plugin Org.projectlombok lombok table construction
Create a test table in the database, the table is relatively simple, try it first. Sql is as follows:
CREATE TABLE `test_fluent_ mybatis` (`id` int NOT NULL AUTO_INCREMENT COMMENT 'self-increasing primary key', `name` varchar (255) DEFAULT NULL COMMENT 'name', `age`time` 'age', `create_ time`datetime DEFAULT NULL COMMENT 'creation time', `del_ time`int DEFAULT NULL COMMENT 'whether to delete', PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; code generation tool class
Note: put it in the test code package. The structure is as follows:
Code generation tool class code, first according to the official simple example, as follows:
Package com.hy.fmp; import cn.org.atool.generator.FileGenerator;import cn.org.atool.generator.annotation.Table;import cn.org.atool.generator.annotation.Tables;import org.junit.jupiter.api.Test; public class EntityGeneratorDemo {/ / data source url static final String url = "jdbc:mysql://192.168.0.16:3306/test?useUnicode=true&characterEncoding=utf8"; / / database user name static final String username = "root" / / Database password static final String password = "123456"; @ Test public void generate () throws Exception {/ / reference configuration class, build method allows multiple configuration classes FileGenerator.build (Empty.class) } @ Tables (/ / set database connection information url = url, username = username, password = password, / / set entity class to generate src directory, relative to user.dir srcDir = "src/main/java", / / set package value of entity class basePack = "com.hy.fmp.fluent", / / set dao interface and implemented src directory Relative to user.dir daoDir = "src/main/java", / / set which tables to generate the Entity file tables = {@ Table (value = {"test_fluent_mybatis"})}) static class Empty {/ / the class name is random, just a carrier defined by the configuration}}
Execute the code generation tool to see what has been generated.
You can see that the generated package is as follows.
Solve the problem that the class could not be found
There's a hole here. Look at the screenshot below.
In fact, the authorities have given a solution, but did not explain it.
In short, you need to compile it using maven, so let's compile it.
After compilation, we can find the compilation file in the location of the error package in target.
The class that reported the error before is no longer wrong. Perfect.
Thank you for reading this article carefully. I hope the article "how to build a Java Fluent Mybatis project and achieve code generation" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.