Hello friends
Recently, I have used a framework called Mybatis to embed SQL commands for processing as well as create dynamic queries to run the program in (Java) Spring Boot, I would like to share my experience learning Mybatis through this article.
With the purpose of testing Mybatis, the problem will be directed so that we go through all the basic features of Mybatis, not related to any actual problem. Some of the features I would like to use are as follows:
- Write RawSQL to handle the incoming java calls and get the results
- Write SQL Builder form to handle incoming java calls and get the results
- Write SQL for basic syntax: SELECT, INSERT, UPDATE, DELETE
- The problem is to write a program to store user and items data.
So let me start.
0. Environment
My machine’s environment when doing the following:
- OS: MacOS
- IDE: SpringToolSuite4 (Eclipse)
1. Install
1.1. Project initialization
We use Spring Initializr to initialize, very convenient. https://start.spring.io/
The options are as follows
Item | Selection |
---|---|
Project | Maven Project |
Language | Java |
Project Metadata | Same picture |
Dependencies | Mybatis, H2 |
We will use Mybatis so we will choose a dependence called Mybatis.
Regarding the database, I choose Mysql because I am used to manipulating this DB.
Select Generate, we get the zip file, extract it and import it into the IDE, we have the following structure
In which note one parameter is that the mybatis we use has a version of 2.1.3 and this is a specially designed version used with Spring Boot, not the popular version (Currently 3.5.5 )
1 2 3 4 5 6 | <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.3</version> </dependency> |
We also create 2 packages available to store the mybatis classes that will be used later:
- src / main / java / com / demo / mybatis / mapper
- src / main / java / com / demo / mybatis / model
1.2. Database structure
We’ll need a ready-to-use database for the queries to call and execute. We will structure the database as follows:
Create DB mysql with docker
docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | version: '3' services: database: image: mysql:8.0 volumes: - ./db/dbdata:/var/lib/mysql command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password'] environment: MYSQL_DATABASE: demo MYSQL_ROOT_PASSWORD: root MYSQL_USER: demo MYSQL_PASSWORD: demo ports: - "33061:3306" |
We build a database with the user, password, and port information as above. Start with docker-compose up -d
Table structure
(Access the database command line with mysql -h 0.0.0.0 -P 33061 -u demo demo -p
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | CREATE TABLE users ( id int AUTO_INCREMENT primary Key ,name TEXT NOT NULL ,birthday date ); CREATE TABLE items ( id int AUTO_INCREMENT primary Key, name TEXT NOT NULL, user_id INT, FOREIGN KEY (user_id) references users(id) ); |
In this post I tested with a basic user table with the user’s attributes as name (name) and date of birth (birthday). Then the items table contains the foreign key to the users table to test the relationship feature in mybatis.
1.3. Install plugin Mybatis Generator
1.3.1. Download from Marketplace
We can choose to write the necessary classes by ourselves, but another option is to use the Mybatis Generator , which is a very useful tool for the creation of necessary classes using Mybatis.
Homepage: http://mybatis.org/generator/
Mybatis Generator has the ability to look up specified tables and generate classes related to that database, thereby reducing implementation effort a lot.
You can download with the command line, in this article I download as an eclipse plugin as follows: look up from the Eclipse Marketplace (Help -> Eclipse Marketplace) with the keyword Mybatis, choose to download Mybatis Generator 1.4.0
After downloading, we create generatorConfig.xml file to specify the necessary settings for the Generator. I created with the following content:
src / main / resources / generatorConfig.xml
1 2 3 4 5 6 7 8 9 10 11 12 | <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <context id="context1"> <jdbcConnection connectionURL="jdbc:mysql://0.0.0.0:33061/demo" driverClass="com.mysql.cj.jdbc.Driver" password="demo" userId="demo" /> <javaModelGenerator targetPackage="com.demo.mybatis.model" targetProject="mybatis/src/main/java" /> <javaClientGenerator targetPackage="com.demo.mybatis.mapper" targetProject="mybatis/src/main/java"/> <table schema="demo" tableName="users"></table> <table schema="demo" tableName="items"></table> </context> </generatorConfiguration> |
Inside :
- connectionURL : url containing information connecting to the database
- userId : the user name for the database
- password : password for the above user
- javaModelGenerator : specify generate Model classes (User, Item)
- javaClientGenerator : specify generate Mapper and Support classes
- table : specify the table to generate
1.3.2 Generator (Run Configuration)
Run -> Run Configuration -> Mybatis Generator (New)
Here we specify the Configuration File
to the previous config file in 1.3.1.
2. Write the program
2.1.Run Generator
Try Run with the above configuration, we get the log in the Console as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | MyBatis Generator Started... Buildfile: /Users/*****/Projects/blogs/.metadata/.plugins/org.mybatis.generator.eclipse.ui/.generatedAntScripts/demo-generator.xml 21:55:18.905 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.eclipse.ui.ant.logging.AntLogFactory - Logging initialized using 'org.mybati <a class="__cf_email__" href="/cdn-cgi/l/email-protection">[email protected]</a> 5a170dff' adapter. 21:55:18.920 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.logging.LogFactory - Logging initialized using ' <a class="__cf_email__" href="/cdn-cgi/l/email-protection">[email protected]</a> cb7' adapter. 21:55:19.460 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.internal.db.DatabaseIntrospector - Retrieving column information for table "demo.users" 21:55:19.525 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.internal.db.DatabaseIntrospector - Found column "id", data type 4, in table "demo..users" 21:55:19.525 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.internal.db.DatabaseIntrospector - Found column "name", data type -1, in table "demo..users" 21:55:19.525 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.internal.db.DatabaseIntrospector - Found column "birthday", data type 91, in table "demo..users" 21:55:19.538 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.internal.db.DatabaseIntrospector - Retrieving column information for table "demo.items" 21:55:19.545 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.internal.db.DatabaseIntrospector - Found column "id", data type 4, in table "demo..items" 21:55:19.545 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.internal.db.DatabaseIntrospector - Found column "name", data type -1, in table "demo..items" 21:55:19.545 [Worker-6: Launching demo-generator] DEBUG org.mybatis.generator.internal.db.DatabaseIntrospector - Found column "user_id", data type 4, in table "demo..items" BUILD SUCCESSFUL MyBatis Generator Finished |
After finishing running, we get the following classes generated:
Mybatis Generator provides us with the following 3 basic classes:
- Models: Class that models the results as well as parameters of SQL statements, usually equivalent to a table in the database.
- Mapper: is the class that stores the queries that we use to query the database
- The Support: write handling support with Mapper by providing the instance variables corresponding to the table structure
We will look at the contents of these files:
2.1.1 Models (Users and Items)
src / main / java / com / demo / mybatis / model / Users.java
1 2 3 4 5 6 7 8 9 10 11 | public class Users { @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.209677+09:00", comments = "Source field: users.id") private Integer id; @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.209787+09:00", comments = "Source field: users.birthday") private Date birthday; @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.209838+09:00", comments = "Source field: users.name") private String name; ... các getter và setter |
We can see that Mybatis Generator generated all the fields the users table contained (id, name, birthday) and mapped them to the nearest data type (Integer, Date, String).
Each field has an annotation that marks how well they are generated.
2.1.2. Mapper
Mybatis generate for us more than 2 dozen utility functions, we will go through some initial functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package com.demo.mybatis.mapper; import .... @Mapper public interface ItemsMapper { @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.213504+09:00", comments = "Source Table: items") BasicColumn[] selectList = BasicColumn.columnList(id, userId, name); @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.212724+09:00", comments = "Source Table: items") @SelectProvider(type = SqlProviderAdapter.class, method = "select") long count(SelectStatementProvider selectStatement); @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.212767+09:00", comments = "Source Table: items") @DeleteProvider(type = SqlProviderAdapter.class, method = "delete") int delete(DeleteStatementProvider deleteStatement); @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.212805+09:00", comments = "Source Table: items") @InsertProvider(type = SqlProviderAdapter.class, method = "insert") int insert(InsertStatementProvider<Items> insertStatement); ... các hàm khác |
- selectList : contains a list of fields corresponding to the corresponding model.
- long count () : function counts the list based on the select command given parameter. Then we can count the number of records that satisfy the condition by calling the ItemsMapper.count (…) command.
- int delete () : the function deletes the record based on a condition passed in a parameter
- int insert () : similar to the two above functions with the insert command
2.1.3. support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | package com.demo.mybatis.mapper; import java.sql.JDBCType; import java.util.Date; import javax.annotation.Generated; import org.mybatis.dynamic.sql.SqlColumn; import org.mybatis.dynamic.sql.SqlTable; public final class UsersDynamicSqlSupport { @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.210459+09:00", comments = "Source Table: users") public static final Users users = new Users(); @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.210567+09:00", comments = "Source field: users.id") public static final SqlColumn<Integer> id = users.id; @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.210599+09:00", comments = "Source field: users.birthday") public static final SqlColumn<Date> birthday = users.birthday; @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.210625+09:00", comments = "Source field: users.name") public static final SqlColumn<String> name = users.name; @Generated(value = "org.mybatis.generator.api.MyBatisGenerator", date = "2020-08-23T14:46:02.210527+09:00", comments = "Source Table: users") public static final class Users extends SqlTable { public final SqlColumn<Integer> id = column("id", JDBCType.INTEGER); public final SqlColumn<Date> birthday = column("birthday", JDBCType.DATE); public final SqlColumn<String> name = column("name", JDBCType.LONGVARCHAR); public Users() { super("users"); } } } |
Inside each Support class there is a subclass representing the table that points to ( Users ), this subclass contains properties corresponding to the fields of the table it points to.
The parent Support class ( UsersDynamicSqlSupport ) contains an instance of that subclass, and each other property is a reference to the property of that instance.
We will actually use the above properties later.
2.2 Writing test treatments using mybatis
2.2.1.Write custom Model and Mapper for relationship between Items and Users
This paragraph can be a bit advanced, above I used Mybatis Generator to generate the models and mapper for each table in the database.
However, I want to use a mapper of the form that can be used with a relationship between the tables, and requires joining . This feature, Mybatis Generator still does not support creating a suitable class and mapper.
1 2 | Join queries will likely require you to define a MyBatis result mapping in XML. This is the only instance where XML is required. This is due to the limitations of the MyBatis annotations when mapping collections. |
https://mybatis.org/mybatis-dynamic-sql/docs/select.html
Therefore, I created a new one
2.2.1.1.ItemsUsers (Model)
src / main / java / com / demo / mybatis / model / ItemsUsers
1 2 3 4 5 6 7 8 | package com.demo.mybatis.model; public class ItemsUsers { private int item_id; private int user_id; private String user_name; private String item_name; |
These are the 4 properties that I want to get out after joining the 2 tables together.
2.2.1.2.ItemsUsersMapper.java
Similarly, we will create a Mapper containing a call to handle the relationship between the two tables. src / main / java / com / demo / mybatis / mapper / ItemsUsersMapper
1 2 3 4 5 6 7 8 9 10 11 12 13 | package com.demo.mybatis.mapper; import java.util.List; import org.apache.ibatis.annotations.Mapper; import com.demo.mybatis.model.ItemsUsers; @Mapper public interface ItemsUsersMapper { List<ItemsUsers> selectCommon(); } |
2.2.1.3.ItemsUsersMapper.xml
src / main / java / com / demo / mybatis / mapper / ItemsUsersMapper.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.demo.mybatis.mapper.ItemsUsersMapper"> <select id="selectCommon" resultType="com.demo.mybatis.model.ItemsUsers"> SELECT users.id as user_id, items.id as item_id, users.name as user_name, items.name as item_name FROM users JOIN items ON items.user_id = users.id; </select> </mapper> |
Here we have created a pure query containing the join command. Spring can detect and attach this xml with its corresponding java mapper.
Note that in the query we need to declare the correct id with the function name in the java mapper and the correct return type.
( Although the return type is List, mybatis still accepts the resultType declaration, which is not an explicit type of List, but an element. )
2.2.2 Create a playground
The Playground I mean here is the class used exclusively for testing, trying out new handlers for the first time. We will write basic handling with the model in this playground.
src / main / java / com / demo / mybatis / MybatisPlayground.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | package com.demo.mybatis.mapper; import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo; import java.text.ParseException; import java.util.Date; import com.demo.mybatis.model.Items; import com.demo.mybatis.model.Users; public class MybatisPlayground { private UsersMapper usersMapper; private ItemsMapper itemsMapper; public MybatisPlayground(UsersMapper usersMapper, ItemsMapper itemsMapper) { this.usersMapper = usersMapper; this.itemsMapper = itemsMapper; } .... |
We let the parameter pass in to initialize the mapper to be used, while the mapper will be initialized for Spring to handle outside.
For the purpose of testing using mybatis, I create functions that go through basic queries such as delete, select, update, insert
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | // Thử nghiệm query delete public void deleteALlUsers() { itemsMapper.delete(i -> i); usersMapper.delete(u -> u); } // Thử nghiệm query insert thường public void sampleInsertUsers(String userName, Date birthday) throws ParseException { Users users = new Users(); users.setName(userName); users.setBirthday(birthday); usersMapper.insert(users); } // Thử nghiệm query update public void sampleUpdateUsers(String userName1, String userName2) { Users users = usersMapper.selectOne(u -> u.where(UsersDynamicSqlSupport.name, isEqualTo(userName1))).get(); users.setName(userName2); usersMapper.updateByPrimaryKey(users); } // Thử nghiệm insert với relationship public void sampleInsertItems(String userName, String itemName) { Users users = usersMapper.selectOne(u -> u.where(UsersDynamicSqlSupport.name, isEqualTo(userName))).get(); Items items = new Items(); items.setName(itemName); items.setUserId(users.getId()); itemsMapper.insert(items); } |
One interesting point when using mybatis is that I was able to use lambda type handling for these function calls.
At this point, the basic processing is complete, then we will fix it at the program’s initialization process to call these processes.
2.2.3 Editing MybatisApplication
This is the clue to start the program, currently only Spring startup. We will edit to call the mybatis handler tests above.
src / main / java / com / demo / mybatis / MybatisApplication.java
1 2 3 4 5 6 | @Autowired UsersMapper usersMapper; @Autowired ItemsMapper itemsMapper; |
The plugin mybatis at the beginning of the load is not simply mybatis but the version that has been processed for the utility with Spring. With this utility, we just need to declare the Autowire mapper annotation to be detected by Spring and initialized at the start of the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | @Bean public CommandLineRunner testInsert(ApplicationContext ctx) { return args -> { MybatisPlayground ground = new MybatisPlayground(usersMapper, itemsMapper); ground.deleteALlUsers(); // Init user 1 String userName = "test user 1"; String birthdayAsStr = "2010-12-01"; DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); Date birthday = format.parse(birthdayAsStr); ground.sampleInsertUsers(userName, birthday); ground.sampleUpdateUsers("test user 1", "test user 2"); ground.sampleInsertItems("test user 2", "test item 1"); ground.sampleInsertItems("test user 2", "test item 2"); }; } |
With the Bean annotation declaration and the function template as above, Spring will detect and call by itself, so we do not need to fix at main ()
Above we declared to call all the handlers that created playgrounds.
2.2.4.Write JUnit
We will write unit test with JUnit to check if the functions are working properly, as well as test if the Mapper with the Join type works properly.
src / test / java / com / demo / mybatis / MybatisApplicationTests.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | package com.demo.mybatis; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import com.demo.mybatis.mapper.ItemsUsersMapper; import com.demo.mybatis.mapper.UsersMapper; import com.demo.mybatis.model.ItemsUsers; @SpringBootTest class MybatisApplicationTests { @Autowired UsersMapper usersMapper; @Autowired ItemsUsersMapper itemsUsersMapper; @Test void contextLoads() { // Kiểm tra xem bảng users chỉ có một phần tử được tạo long totalRows = usersMapper.count(c -> c); assertEquals(totalRows, 1); // Kiểm tra xem mapper cho relationship thực sự lấy ra được 2 item. List<ItemsUsers> listItemsUsers = itemsUsersMapper.selectCommon(); assertEquals(listItemsUsers.get(0).getItem_name(), "test item 1"); assertEquals(listItemsUsers.get(0).getUser_name(), "test user 2"); assertEquals(listItemsUsers.get(1).getItem_name(), "test item 2"); assertEquals(listItemsUsers.get(1).getUser_name(), "test user 2"); } } |
3. Run the program
We can run the program with Run Configuration with Project as mybatis and Main class com.demo.mybatis.MybatisApplication as shown in the picture.
we get results
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | . ____ _ __ _ _ /\ / ___'_ __ _ _(_)_ __ __ _ ( ( )___ | '_ | '_| | '_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.3.3.RELEASE) 2020-08-26 23:55:44.663 INFO 7499 --- [ main] com.demo.mybatis.MybatisApplication : Starting MybatisApplication on TrannoMacBook-Pro.local with PID 7499 (/Users/tranvanmy/Projects/blogs/mybatis/target/classes started by tranvanmy in /Users/tranvanmy/Projects/blogs/mybatis) 2020-08-26 23:55:44.666 INFO 7499 --- [ main] com.demo.mybatis.MybatisApplication : No active profile set, falling back to default profiles: default 2020-08-26 23:55:45.740 INFO 7499 --- [ main] com.demo.mybatis.MybatisApplication : Started MybatisApplication in 1.616 seconds (JVM running for 2.045) 2020-08-26 23:55:45.766 INFO 7499 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2020-08-26 23:55:46.215 INFO 7499 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2020-08-26 23:55:46.512 INFO 7499 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2020-08-26 23:55:46.544 INFO 7499 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. |
or run with maven: ./mvnw spring-boot: run
After running, we get the inserted database structure:
Users table
id | name | birthday |
---|---|---|
32 | test user 2 | 2010-12-01 |
Table of items
id | name | birthday |
---|---|---|
22 | test item 1 | 32 |
23 | test item 2 | 32 |
Next, we will run the test to see if the join command has been modeled into xml and the call runs properly. This time I’ll run with Maven
1 2 | ./mvwn test |
Result
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | .... . ____ _ __ _ _ /\ / ___'_ __ _ _(_)_ __ __ _ ( ( )___ | '_ | '_| | '_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.3.3.RELEASE) 2020-08-27 00:02:42.731 INFO 7755 --- [ main] c.demo.mybatis.MybatisApplicationTests : Starting MybatisApplicationTests on TrannoMacBook-Pro.local with PID 7755 (started by tranvanmy in /Users/tranvanmy/Projects/blogs/mybatis) 2020-08-27 00:02:42.733 INFO 7755 --- [ main] c.demo.mybatis.MybatisApplicationTests : No active profile set, falling back to default profiles: default 2020-08-27 00:02:44.134 INFO 7755 --- [ main] c.demo.mybatis.MybatisApplicationTests : Started MybatisApplicationTests in 1.649 seconds (JVM running for 2.654) 2020-08-27 00:02:44.163 INFO 7755 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2020-08-27 00:02:44.633 INFO 7755 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.486 s - in com.demo.mybatis.MybatisApplicationTests 2020-08-27 00:02:45.530 INFO 7755 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2020-08-27 00:02:45.558 INFO 7755 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. [INFO] [INFO] Results: [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.078 s [INFO] Finished at: 2020-08-27T00:02:45+09:00 [INFO] ------------------------------------------------------------------------ |
-> Running with 0 errors, call handling seems to work fine!
4.Conclusion
At this point, I have shared about how to use Mybatis and Mybatis Generator to embed SQL commands in processing as well as call dynamic SQL queries with Spring Boot framework.
Hope to be helpful for you with related professionalism.
Source code: https://github.com/mytv1/mybatis-sample
Reference: https://qiita.com/kazuki43zoo/items/ea79e206d7c2e990e478
Over.