Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the use of MyBatis Plus?

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you what is the use of MyBatis Plus, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

MyBatis Plus is a MyBatis enhancement tool developed by domestic personnel, which is only enhanced but not changed on the basis of MyBatis, in order to simplify development and improve efficiency.

The core functions of MyBatis Plus are: support for general CRUD and conditional constructors.

General CRUD: after defining the Mapper interface, you only need to inherit the BaseMapper interface to obtain the general function of adding, deleting, modifying and querying, without writing any interface methods and configuration files.

Conditional constructor: through EntityWrapper (entity wrapper class), it can be used to concatenate SQL statements and support complex SQL such as sorting and grouping queries.

two。 Add dependency

Com.baomidou

Mybatis-plus

2.3

3. Configuration

4.Dao layer

Public interface IUserDao extends BaseMapper {

}

5. Entity class

@ Data

@ TableName (value= "t_user")

Public class User {

TableId (value= "id", type=IdType.AUTO)

Private Integer id

@ TableField (value= "username")

Private String name

Private Integer age

Private String password

@ TableField (exist=false)

Private Integer xxx

}

6. Common notes

@ TableField (exist = false): indicates that the property is not a database table field, but must be used.

@ TableField (exist = true): indicates that the attribute is a database table field.

@ TableName: related to database tables

@ TableId: table primary key identification

@ TableField: table field identification

7. Testing method

@ Test

Public void testMybatisPlus () {

System.out.println ("selectById:" + userDao.selectById (4)); / / query according to Id

System.out.println ("selectList:" + userDao.selectList (null)); / / query all

Com.baomidou.mybatisplus.plugins.Page page = new com.baomidou.mybatisplus.plugins.Page ()

List list = userDao.selectPage (page, null); / / paging query

Page.setRecords (list); / / encapsulate the result in a paging object

System.out.println (page.getCurrent ())

System.out.println (page.getPages ())

System.out.println (page.getSize ())

System.out.println (page.getTotal ())

System.out.println (page.getRecords ())

EntityWrapper entityWrapper = new EntityWrapper ()

EntityWrapper.eq ("id", 4)

EntityWrapper.or (. Like ("username", "3")

List selectList = userDao.selectList (entityWrapper); / / conditional query

System.out.println ("wrapper:" + selectList)

}

The above is all the content of this article "what's the use of MyBatis Plus?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report