zoukankan      html  css  js  c++  java
  • @JsonIgnore注解|@JsonProperty

    注解名称:@JsonIgnore
    作用:在实体类向前台返回数据时用来忽略不想传递给前台的属性或接口。
    Eg:Bean实体中会有某些运维字段,在返回信息给前台的时候,当不希望将对应值也一并返回;
      此时可以在对应属性上加上注解JsonIgnore或者,可以在User类上加上注解@JsonIgnoreProperties(value = "{password}")

    以下是给出一个小Demo供测试参考:

    
    
    public class WiBean {
    
        
        // 忽略参数返回
        @JsonIgnore
        private String names;
        
        // 用于属性上、set/get方法上,该属性序列化后可重命名。
        @JsonProperty(value="val")
        private String values;
    
        @JsonIgnore
        public String getNames() {
            return names;
        }
    
        public void setNames(String names) {
            this.names = names;
        }
    
        @JsonProperty(value="val")
        public String getValues() {
            return values;
        }
    
        public void setValues(String values) {
            this.values = values;
        }
        
        
    }
    public class GoControl {
    
    //    @JsonIgnore
    //    @JsonProperty
        
        
        public static JSONObject printParam(){
            WiBean bean = new WiBean();
            bean.setNames("key");
            bean.setValues("value");
            
            return JSONObject.fromObject(bean);
        }
        
        public static void main(String[] args) {
            WiBean bean = new WiBean();
            bean.setNames("tan");
            bean.setValues("dalei");
            try {
                System.out.println(new ObjectMapper().writeValueAsString(bean));
            } catch (JsonGenerationException e) {
                e.printStackTrace();
            } catch (JsonMappingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        
    }
  • 相关阅读:
    修改MySQL密码
    struts入门
    监听
    游戏外挂教程(转)
    “无法加载一个或多个请求的类型。有关更多信息,请检索 LoaderExceptions 属性 “之解决
    C# PropertyGrid控件应用心得
    登录时的"记住我"
    自动登录、记住我(保存登陆状态)实现
    UpdatePanel的使用方法
    asp.net中使用基于角色role的Forms验证
  • 原文地址:https://www.cnblogs.com/tanjiyuan/p/11058936.html
Copyright © 2011-2022 走看看