How to use mybatis.type-aliases-package
This article mainly explains "how to use mybatis.type-aliases-package". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use mybatis.type-aliases-package.
Usage instructions for mybatis.type-aliases-package
Custom POJO is used in the type or parameterType of resultMap in the mapper.xml file.
For example:
Select * from User select * from User where username=# {username} select password from user where username=# {username} insert into user (username,password) value (# {username}, # {password})
In resultType= "User", User is a custom POJO. You can use a fully qualified name to specify references to these POJO, for example:
The second method is to use mybatis.type-aliases-package to specify the POJO scan package to have mybatis scan to the custom POJO automatically.
Configure the following information in the application.propertites configuration file: mybatis.type-aliases-package=com.example.entity
Several problems in using mybatis.type-aliases-package=com.example.demo.entitytype-aliases-package
Custom POJO is often used in resultType in mapper.xml, and you can specify references to these POJO with fully qualified names, such as
SELECT T.* FROM student T
We need to query the information of all the students in the student table, define an entity class student to map all the student information in the table, and put the permission of the class in the resultType tag. When the underlying mybatis returns the database information, it will generate the object instance according to Class.forName ("cn.wideth.entity.domain.Student").
If we want to use only the class name Student in the resultType tag, is it okay?
SELECT T.* FROM student T
This is also possible, but it needs to be configured in advance in the yml configuration file.
Mybatis: config-location: classpath:mybatis/mybatis-config.xml mapper-locations: classpath:mybatis/mapper/*.xml type-aliases-package: cn.wideth.entity
This is also possible. When springboot starts, it will load the cn.wideth.entity package and all the entity classes under the subpackage for initialization. However, no entity class with the same name can exist under different subpackages.
There is an entity class with the same name under the subpackage, resulting in an error.
Thank you for your reading, the above is the content of "how to use mybatis.type-aliases-package", after the study of this article, I believe you have a deeper understanding of how to use mybatis.type-aliases-package, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!