1. User module management
1.1 Paging Query Using MP
1.1.1 Edit UserController
1.1.2 Edit UserService
/** * Paging Query by MP * API Description: selectPage(arg1,arg2) * arg1: MP Fixed Paging Objects in * arg2: MP Conditional constructors in paging * @param pageResult * @return * Dynamic Sql: select * from user where username like'%admin%' * Conditions: Where condition is stitched if user passes query otherwise where condition is not stitched */ @Override public PageResult getUserList(PageResult pageResult) {//Original 3 parameters //1. Define MP's paging object arg1: Page arg2: Number of rows IPage iPage = new Page(pageResult.getPageNum(), pageResult.getPageSize()); //2. Build Query Conditions Constructor QueryWrapper queryWrapper = new QueryWrapper(); //Determine whether user data is valid valid true invalid false boolean flag = StringUtils.hasLength(pageResult.getQuery()); queryWrapper.like(flag, "username", pageResult.getQuery()); //Encapsulate all paging (total/result/page/number of bars/xxx) data into an iPage object by MP paging query iPage = userMapper.selectPage(iPage,queryWrapper); //Getting Total Records from Paging Objects long total = iPage.getTotal(); //Getting Paged Results from Paging Objects List<User> rows = iPage.getRecords(); return pageResult.setTotal(total).setRows(rows); //Five parameters need to be returned }
1.1.3 MP Paging API
1.1.4 Edit MP Configuration Class
//Naming Rule: Call this class "Configuration Class" at the end of a generic Config, similar to a configuration file @Configuration //Identify me as a configuration class (instead of the previous xml file) public class MybatisPlusConfig { //Padding: Manage objects in xml through labels, leaving them to Spring containers. < Bean> //Configuration class: Give the return value of the method to the Spring Container Management @Bean annotation. /** * Description of MP Paging Rules * Rule: An interceptor needs to be set. Dynamic stitching of paged Sql. * Sql: The Sql now supports the Sql92 standard!!!! Different design concepts */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MARIADB)); return interceptor; } }
1.2 Status Modification
1.2.1 Business Description
Note: When modifying status information, the status property should be modified to enable -true/disable-false
Modify condition: userId/current status information.
1.2.2 Business Interface Description
1.2.3 Front End JS Analysis
- Scope slots are typically used to obtain a single row of data during loop traversal.
- Page Ajax
1.2.4 Edit UserController
1.2.5 Edit UserService
1.3 New Users
1.3.1 Regular Expression
Regular expression, also known as regular expression. (English: Regular Expression, often abbreviated as regex, regexp, or RE in code), is a concept of computer science. Regular expressions are often used to retrieve and replace text that conforms to a pattern (rule).
Many programming languages support string manipulation using regular expressions. For example, a powerful regular expression engine is built into Perl. The concept of regular expressions was first popularized by tool software in Unix, such as sed and grep. Regular expressions are usually abbreviated as "regex", singular as regexp, regex, and complex as regexps, regexes, and regexen.
1.3.2 Regular Expression Syntax
- Start/End
- Number Match
- Number interval usage {}
Example: 3{3,5} 333 3333 333
- Any Character
- Range of Value []
- Group Writing
Case: Type XXX that needs to match the picture. JGP can satisfy only one of them (jpg|png|jpeg|gif)
1.3.3 Regular Expression Grammar Case
- Verify mobile number
const phoneRege = /^1[23456789][0-9]{9}$/
- 1
- Verify mailbox syntax: xxxxx@xxxx.xx
const emailRege = /^[a-zA-Z0-9-_]+@[a-zA-Z0-9-_]+\.[a-zA-Z0-9-_]+$/
- 1
1.3.4 User Added Page JS
- Page JS
- Page URL address
1.3.5 New Business Interface for Users
1.3.6 Edit UserController
1.3.7 Edit UserService
1.4 Data auto-fill
1.4.1 Demand Analysis
Updating a database modifies the creation/modification time of the database. Each table has a similar operation. Therefore, business calls should be made for a public API.
1.4.2 Data auto-fill function
1.4.3 Edit POJO Properties
Description: Set when the POJO property will be automatically populated.
1.4.4 Implement MP auto-fill
Description: MP exposes an auto-populated interface MetaObjectHandler, which users only need to implement and override their methods. That is to achieve the function of automatic filling.
@Component //Delegating objects to Spring container management does not belong to C/S/M public class MyMetaObjectHandler implements MetaObjectHandler { //Call create/updated during a repository operation //setFieldValByName(arg1,arg2,arg3) //arg1: auto-populated field name arg2: auto-populated value arg3: metaObject fixed writing @Override public void insertFill(MetaObject metaObject) { //Set time variable Date date = new Date(); this.setFieldValByName("created",date,metaObject); this.setFieldValByName("updated",date,metaObject); } //Call update during update operation @Override public void updateFill(MetaObject metaObject) { this.setFieldValByName("updated",new Date(),metaObject); } }