Mybatis Overviewfollowing the article, today, SE Tran Duy Truong of NAL is going to help readers to have a better understanding of how Mybatis works by showing how to configure Mybatis.
Mybatis Overviewfollowing the article, today, SE Tran Duy Truong of NAL is going to help readers to have a better understanding of how Mybatis works by showing how to configure Mybatis.
1. Configure MyBatis with the XML file and some essential tags when configuring the file.
- I create a file named mybatis-config.xml (image)
- You can see that the above code has a lot of tags. So what is the meaning of these tags ??
+ Tag
+ Tag
+ Tag
Latest Products
+ Tag
For example:<mappers><マッパーリソース = "mybatis/ Student.xml"/></mappers>
2. How to query data using XML file
Below is an example:
In the above code, we can see that using MyBatis to access data using the XML file is quite easy. We need to map the column name in the database table through the tag
Note: when using XML to query, we need to point to the correct id
3. How to query data using Annotation
Just like how to query data when using XML, we only need to create an interface to access data when using Annotation. In the interface, the user will declare queries and then use annotations to map SQL.
For example: public interface StudentMapper {
Original article:https://media.nal.vn/mybatis-config