SpringBoot and MyBatis and MySQL, the hello world example
This post would demo how to run a hello world example on springboot+MyBatis+MySQL.
The database table:
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.
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: