web development gadget, zero foundation, how to change to front-end development engineer

preface

How to verify parameters? Lu Zhu's projects a long time ago were "if else" one by one on the front-end page. Later, he used a series of front-end verification frameworks, such as "layui" and "iview". Several style attributes can be easily done. It's really beautiful.

Back end validation

So here comes the question...? The front end has been verified. Is it necessary to verify the back end?

If you have to have a result, the answer can only be unsafe. Although the client has verified itself, it can not avoid some malicious users from artificially modifying the form and directly sending spoofing requests.

Therefore, from the perspective of security, it is not safe to rely solely on front-end verification. Any robust system must be verified at the back-end.

Of course, you don't have to worry about writing another if else in the background. Here we recommend a parameter verification artifact, hibernate validator. SpringBoot's standard JPA comes with it, so you can use it directly.

annotation

It basically provides common verification annotations. If it does not meet the business requirements, you can define your own regular expression through @ Pattern.

@Null  The annotated element must be null
@NotNull  Annotated element cannot be null null
@AssertTrue  The annotated element must be true
@AssertFalse  The annotated element must be false
@Min(value)  The annotated element must be a number and its value must be greater than or equal to the specified minimum value
@Max(value)  The annotated element must be a number and its value must be less than or equal to the specified maximum value
@DecimalMin(value)  The annotated element must be a number and its value must be greater than or equal to the specified minimum value
@DecimalMax(value)  The annotated element must be a number and its value must be less than or equal to the specified maximum value
@Size(max,min)  The size of the annotated element must be within the specified range.
@Digits(integer,fraction)  The annotated element must be a number and its value must be within an acceptable range
@Past  The annotated element must be a past date
@Future  The annotated element must be a future date
@Pattern(value) The annotated element must conform to the specified regular expression.
@Email The annotated element must be an e-mail address
@Length The size of the annotated string must be within the specified range
@NotEmpty  The annotated string must be non empty
@Range  The annotated element must be within the appropriate range

case

Take user registration as an example:

@Data
@Entity
@Table(name = "sys_user")
public class SysUser implements Serializable{
   /**
    * User id
    */ 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id", nullable = false, length = 20)
    private Long userId;

   /**
    * user name
    */
    @NotNull
    @Column(name = "username", nullable = false, length = 50)
    private String username;

   /**
    * password
    */
    @Size(min = 6, max = 25, message = "The password length should be between 6 and 25")
    @Column(name = "password", nullable = false, length = 50)
    private String password;

   /**
    * Name (nickname)
    */ 
    @NotNull
    @Column(name = "nickname", length = 50)
    private String nickname;

   /**
    * mailbox
    */
    @Email(message="The mailbox format is incorrect")
    @Column(name = "email", length = 100)
    private String email;

   /**
    * cell-phone number
    */
    @Pattern(regexp="^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$",message="Incorrect phone format")
    @Column(name = "mobile", length = 100)
    private String mobile;
   /**
    * Status 0: disabled, 1: normal
    */ 
    @Column(name = "status", length = 4)
    private Short status;

   /**
    * remarks
    */ 
    @Column(name = "remark", length = 500)
    private String remark;

   /**
    * Create user id
    */ 
    @Column(name = "user_id_create")
    private Long userIdCreate;

   /**
    * Creation time
    */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "gmt_create")
    private Timestamp gmtCreate;

   /**
    * Modification time
    */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "gmt_modified")
    private Timestamp gmtModified;
}

Summary

Isn't it great? You don't have to} if else anymore. Of course, it hasn't been verified in the background. Finally, I suggest you to make full safety verification, save the wrangling between the front and rear ends, and the most important thing is to avoid back pot!!!

last

We can still talk about the seven vue modes, but there are too many development skills for the 36 vues. I have written two examples, and the remaining partners simply believe me "vue"


Click here for free , don't forget to get the information.

...(img-Eu8Pudfc-1626947388331)]
[external chain picture transferring... (img-7Pr7tcO8-1626947388334)]
Click here for free , don't forget to get the information.

Keywords: Front-end Interview Programmer

Added by DarkPrince2005 on Sat, 15 Jan 2022 23:41:13 +0200