transient修饰符的作用

transient修饰符的作用:

entity实体类:

package com.baidu.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.data.annotation.Transient;

import java.io.Serializable;

public class User implements Serializable{
    private static final long serialVersionUID = 8121761080892505330L;
    private String username;
    @Transient
    @JsonIgnore
    private transient String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

Controller:

@RequestMapping("/select")
    @ResponseBody
    public BaseResponse select(@RequestBody UserParam userParam){
        //用户重置
        userParam.setUsername("李雪雷2");
        userParam.setPassword("666662");
        try{
            List<User> users = userService.select();
            return BaseResponse.successCustom().setData(users).build();
        }catch (Exception e){
            e.printStackTrace();
            return BaseResponse.failedCustom("系统异常").build();
        }
    }

结果:

原文地址:https://www.cnblogs.com/super-chao/p/8393788.html