后端小技巧--tips

1.枚举使用

public enum TypeEnum {original(0, "对话"),// reply(1, "交谈"),// ; private String description; private int type; private static Map statusMap; static { statusMap = new HashMap(); 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; } }

【后端小技巧--tips】2.序列化 Jackson
@JsonView 简单介绍
通过添加@jsonView 注解指定输出对象
objectMapper.writerWithView(User.WithoutPasswordView.class).writeValue(bos, user);

    推荐阅读