Three Stages of Java Learning - Day13

Posted by ddemore on Thu, 20 Jan 2022 05:20:55 +0100

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

  1. Scope slots are typically used to obtain a single row of data during loop traversal.
  2. 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

  1. Start/End
  2. Number Match
  3. Number interval usage {}
    Example: 3{3,5} 333 3333 333
  4. Any Character
  5. Range of Value []
  6. 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

  1. Verify mobile number
 const phoneRege = /^1[23456789][0-9]{9}$/

   
  • 1
  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

  1. Page JS
  2. 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);
    }
}

Topics: Java Mybatis mybatis-plus