In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the MyBatis and jeesite multi-table query method related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this MyBatis and jeesite multi-table query method article will have a harvest, let's take a look at it.
Sometimes we often encounter multi-level joint search, such as checking role information through a function A table, but there is no direct relationship between A table and role table, so we need to associate it through user table. Therefore, we need multi-level association query (the following is only an example, the actual application users and roles will not design fields in this way)
Handwritten resultMap and query statements in MyBatis xml files
1. MyBatis configuration file: because data binding is done through column (database field name) and property (entity class object name), if the same field name exists, you can modify the field name with as or make special binding.
Select a. Table dagger u.roletrainidrect r.rolelightname from xxxx a left join user u on a.user_id = u.user_id left join role r on r.role_id = u.role_id II, use the @ Table annotation @ Table (name= "Test", alias= "a", label= "test table", columns= {@ Column (name= "testid", attrName= "testid", label= "test ID", isPK=true), @ Column (name= "userid", attrName= "userid") Label= "user id"), @ Column (includeEntity=DataEntity.class),}, joinTable = {@ JoinTable (type= JoinTable.Type.LEFT_JOIN,entity = User.class, alias = "c", on = "c.user_id = a.user_id", attrName= "user", columns = {@ Column (name = "user_name", attrName= "username", label= "user name") @ Column (name = "role_id", attrName= "roleId", label= "role id"),}), @ JoinTable (type= JoinTable.Type.LEFT_JOIN,entity = Role.class, alias = "d", on = "d.role_id = c.role_id", attrName= "role", columns = {@ Column (name = "role_name", attrName= "rolename", label= "role name") }),}, orderBy= "a.update_date DESC") public class Utest extends DataEntity {private static final long serialVersionUID = 1L Private User user; private Role role; private String testid; / / component ID}
Omit the get and set methods, and directly call the finList, findPage and other query methods of jeesite to use the data structure. Just debug yourself.
Add: the following describes the implementation of jeesite complex query statements
At the beginning of development with jeesite, we occasionally encounter a lot of problems, and there are generally many solutions.
First, when querying multiple tables, how to add the conditions of the child tables for the query?
For example: there is a file information table file, which is associated with the user table user and stores a user_id, which needs to be fuzzy queried according to the user's name.
Method 1: when the front end binds the control value with beetl, path presses the object name. Bind the variable name. It is worth noting that remember to add the query condition like:queryType=QueryType.LIKE to the annotation of the userName field of the User class.
Method 2: manually assign the value in the background code, add the userName variable to the file entity class, and call the method after the userName parameter is received in the background
File.getSqlMap (). GetWhere (). And ("c.user_name", QueryType.LIKE, "Zhang"); this is the end of this article on "MyBatis and jeesite multi-table query methods". Thank you for reading! I believe you all have a certain understanding of "MyBatis and jeesite multi-table query methods". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.