The most powerful project in the history: the realization of user's microservice function

We have analyzed the users of the system, including the users of the background management system and the users of the front-end portal. In theory, the two should be managed separately. But for our project, there is no need to do such comprehensive and complex functions in the early stage, so at present, we will put two types of users together. We will analyze the functions that users' micro services need to provide from the user login registration page.

Login page:

Registration page:

1. Demand analysis

From the login and registration pages, we should provide at least the following functions:

(1) According to the user name + password, the mobile number + password is used to log in.

(2) Send SMS verification code to the specified mobile phone number.

In addition to the requirements function seen on the interface, there are also some hidden requirements:

(1) User name and mobile number must be globally unique.

(2) User's add, delete, change and query function.

2. Engineering development of ly server user API

2.1 introduce dependency

    <!-- Integrate swagger -->
    <!--Entity class verification dependency-->

2.2 user entity class

@Table(name = "tb_user")
@ApiModel(description = "user")
public class User {

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "Unique identification id", dataType = "Long")
    private Long id;

    @Length(min = 6, max = 30, message = "User name can only be in 6~30 Between bits")
    @ApiModelProperty(value = "User name", dataType = "String")
    private String username;

    @Length(max = 20, message = "No more than 20 nicknames allowed")
    @ApiModelProperty(value = "Nickname?", dataType = "String")
    private String displayName;

    @ApiModelProperty(value = "Password", dataType = "String")
    private String password;

    @Pattern(regexp = "^1[35678]\\d{9}$", message = "Incorrect format of mobile number")
    @ApiModelProperty(value = "Phone number", dataType = "String")
    private String phone;

2.2.1 data structure

CREATE TABLE `tb_user` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL COMMENT 'User name',
  `display_name` varchar(255) NOT NULL COMMENT 'Nickname?',
  `password` varchar(255) NOT NULL COMMENT 'Password, encrypted storage',
  `phone` varchar(20) DEFAULT NULL COMMENT 'Register mobile number',
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`) USING BTREE

2.3 user microservice operation code

public enum UserResultCode implements ResultCode {

    USER_IS_EXIST(false, 20001, "User name already exists"),
    USER_IS_NOT_EXIST(false, 20002, "The user with the specified unique identity does not exist");

    private boolean success;
    private int code;
    private String message;

2.4 user microservice response body

public class UserResponseResult extends ResponseResult {

     * user
    private User user;

    public UserResponseResult(ResultCode resultCode, User user) {
        this.user = user;

    public User getUser() {
        return user;

    public void setUser(User user) {
        this.user = user;

2.5 user microservice client interface

It is only an empty interface for the time being, and specific interface methods will be added later.

public interface UserApi {

2.6 engineering structure

So far, the ly server user API engineering code has been completed, and the engineering code structure is as follows:

-End- For more details, you can scan the code to pay attention to the WeChat public number.

138 original articles published, 27 praised, 70 thousand visitors+
Private letter follow

Keywords: Mobile Spring Hibernate

Added by j_70 on Sun, 12 Jan 2020 10:42:11 +0200