后端小技巧--tips

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);  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,958评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,958评论 19 139
  • 其实计算机网络一般Java程序员也不用了解,但如果你很清楚网络知识,一定会让面试官刮目相看。 1、HTTP 状态码...
    小G哥哥阅读 795评论 0 0
  • 辍学。 乐华的爸爸从四川回来了,但是一路颠簸,身上一分钱也没存下来。乐华一直盼望着爸爸回来的欢乐情景,结果爸爸却静...
    kww007阅读 608评论 0 0
  • 铅笔画 杜鹃
    嘲笙阅读 271评论 2 5