This update is as follows

  1. Enable JWT key configuration permission
  2. Discard FastJson and use Jackson instead

JWT key configuration permissions

Override this method in the configuration class

@Override
public JWTConfig jwtConfig(a) {
     JWTConfig jwtConfig = new JWTConfig();
     // Unit of token expiration time. Default: second
     jwtConfig.setCalendarField(Calendar.SECOND);
     // Token validity duration. Default: 86400 seconds
     jwtConfig.setCalendarInterval(86400);
     // Private key, default: a UUID
     jwtConfig.setSecret(UUID.randomUUID().toString());
     return jwtConfig;
}
Copy the code

What are the effects of switching to Jackson

Except for the entity class mappings, the rest is unaffected

Field mapping of entity classes

This annotation can be used to resolve the mismatch between entity class names and database fields because the entity class names are humped and database fields are underlined:

com.fasterxml.jackson.annotation.JsonProperty
Copy the code

Add this annotation to the fields of the entity class and set the name property to the database field name

public class TestPO{

    @jsonProperty (value = "name ")
    private String name;
    @jsonProperty (value = "age ")
    private String age;
    @jsonProperty (value = "select id from database ")
    private int id;

}
Copy the code

Two, avoid inconsistent field error

  • Sometimes, the result set of our query will have fields that are not found in the entity class
  • For example, the entity class has fields A, B but the result set has fields A, B, C, which doesn’t exist in the entity class
  • An exception will occur in this case, so to avoid it, use this annotation:
com.fasterxml.jackson.annotation.JsonIgnoreProperties
Copy the code

Add this annotation to the entity class

@JsonIgnoreProperties(ignoreUnknown = true)
public class TestPO{}Copy the code

Specify the date format

When a Date type is present in an entity class, an exception will occur when performing database operations. Therefore, you need to specify a Date format.

com.fasterxml.jackson.annotation.JsonFormat
Copy the code

Add this annotation to the entity class

@JsonIgnoreProperties(ignoreUnknown = true)
public class TestPO{

    @JsonProperty("create_time")
    @ JsonFormat (pattern = "MM - dd yyyy - HH 🇲 🇲 ss")
    private Date createTime;

}
Copy the code

Entity classes need to write get/set methods, or lombok annotations

More information can be found on our website

mars-framework.com