In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to use mybatis-plus to achieve simple multi-table query that does not need to write sql", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to use mybatis-plus to achieve simple multi-table query without writing sql" bar!
Brief introduction
Implement a simple entity class to operate multiple tables. First of all, your project can be used only if you use mybatis-plus.
Design description
How do I associate a table?
Find the attribute name annotated as TableId (mybatis-plus Note) in the first table, and find the same attribute name in every two tables. If it is not found, look for it in reverse. If you haven't found it, look for it one by one. By analogy, the prerequisite for association is that the associated instance name of the master-slave table must be the same.
/ / user Table @ TableIdprivate Integer userId// address Table @ TableIdprivate Integer addressIdprivate Integer userId
instructions
Put the com.freedomen.multipselect package into your project so that the xml in the com.freedomen.multipselect.mapper will be scanned or manually configured, and the com.freedomen.multipselect.service will also be found
/ / introduce service@Autowiredprivate MultipleService multipleService;// table association, associate user table and address table, find all fields of user table and all fields of address table MultipleSelect multipleSelect = MultipleSelect.newInstance ("${1}", new User (), new Address ()); multipleSelect .where ("${0}") .like ("userName", "Zhang San"); multipleService.mulSelect (multipleSelect)
Find field
The first parameter of / / MultipleSelect.newInstance is the field to look for / / ${0} or ${user} table is all the fields of the first table ${0} .username or ${user} .username represents the userName field. By default, all the fields of the first table are returned. The parameter in the middle of ${} can be the subscript of the subsequent entity, or the table name such as user, user_address// all the information under the order table and the user's name and number and address MultipleSelect.newInstance ("${1} .username, ${1} .userphone, ${2}", new Orders (), new User (), new Address ()
Search condition
Eq: = notEq:! = like: LIKE ('% 'has been added in front) between: between and: change the connection mode to AND (default) or: change the connection mode to OR pision: parentheses in: IN notIn: NOT IN notLike: NOT LIKE. Wait
/ / after the instance is ready to find the entity, you can operate the entity / / Note: how the attribute within the entity has a value will be connected by eq as the where condition MultipleSelect multipleSelect = MultipleSelect.newInstance ("${1} .username, ${1} .userphone, ${2}", new Orders (), new User (), new Address () MultipleSelect .where ("${0}") / / which table .eq ("ordersId", 1) / and order id = 1.like ("ordersName", "cmcc") / / and the order name like''% cmcc' .or () / / change the subsequent operation relationship to OR, default to AND .notEq ("orderSno", "123") / / or orderSno is not equal to '123' multipleSelect .where ("${1}") / / which table is followed by the user table default and connection can be changed to OR .in ("userId", [1,2,3]); / / and userId in [1,2,3] multipleSelect .where ("${2}") .or () .like ("adressDetails", "Jiangsu") / / or address like 'Jiangsu' multipleService.mulSelect (multipleSelect); / / query
Sort
/ / MultipleSelect.setOrderBy (... columns) MultipleSelect.setOrderBy ("${1} .ordersName desc", "${2} .UserID asc",...)
Pagination
/ / MultipleSelect.setPage (pageNo, pageSize); MultipleSelect.setPage (1,15); / / 15 articles per page on the first page
MultipleService.mulSelect returns the result
/ / MultipleResult/* prototype private List data; / / result data private Integer pageNo; / / if paging is set, there will be private Integer pageSize; / / if paging is set, there will be private Integer total; / / if paging will be * /
Logical deletion
/ / the TableLogic comment 0 of mybatis-plus is not deleted by default. / / if it is not deleted by 0, you can modify 0 if (logic! = null) sb.append ("AND") .append (te.getNickName ()) .append (".") .append (logic) .append ("=") .append ("0") in the following paragraph of MultipleSelect's setCustomWhere method.
Thank you for your reading, the above is the content of "how to use mybatis-plus to achieve simple multi-table query without writing sql". After the study of this article, I believe you have a deeper understanding of how to use mybatis-plus to achieve simple multi-table query without writing sql. The specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.