美文网首页
后端小技巧--tips

后端小技巧--tips

作者: heiheiwanne | 来源:发表于2016-11-28 12:06 被阅读8次

1.枚举使用

public enum TypeEnum {

    original(0, "对话"),//
    reply(1, "交谈"),//
    ;

    private String description;

    private int type;

    private static Map<Integer, TypeEnum> statusMap;

    static {
        statusMap = new HashMap<Integer, TypeEnum>();
        for (TypeEnum type : TypeEnum.values()) {
            statusMap.put(type.getType(), type);
        }
    }

    public staticTypeEnum getTypeEnum(int type) {
        return statusMap.get(type);
    }

    private TypeEnum(int type, String description) {
        this.type = type;
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public int getType() {
        return type;
    }
}

2.序列化 Jackson
@JsonView 简单介绍
通过添加@jsonView 注解指定输出对象

objectMapper.writerWithView(User.WithoutPasswordView.class).writeValue(bos, user);  

相关文章

网友评论

      本文标题:后端小技巧--tips

      本文链接:https://www.haomeiwen.com/subject/rklopttx.html