SpringBoot and MyBatis and MySQL, the hello world example
Introduction
This post would demo how to run a hello world example on springboot+MyBatis+MySQL.
Environments
SpringBoot 1.5.12
MySQL 5.1.38
Java 1.8
mybatis-spring-boot-starter 1.3.2
The Pom.xml
The database table:
The Classes
Springboot Main entry class:
The domain class:
The Mapper interface:
Here we use a @Mapper to annotate an interface named StudentMapper, which has a method findById, this method is annotated by @Select with a sql statement, just like traditional MyBatis mapper files, but when you use springboot, you don’t need xml now.
The testcase
Here we write a junit test case to test the dao:
As you can see, we just @Autowired the studentMapper, and then use the findById method, then we run the test, we got the green bar and the result:
It’s so easy, do you think so? we would continue to supply more complicated examples some days later.
You can find detail documents about the springboot and unit testing here: