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);