我是靠谱客的博主 娇气小刺猬,最近开发中收集的这篇文章主要介绍返回值vo定义和枚举类定义,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

package com.sinosoft.web.controller.test.Enity;

import lombok.Data;

@Data
public class ResponseVO {

    private Integer code;
    private String message;
    private Object object;


    public ResponseVO() {

    }

    public ResponseVO(Integer code, String message, Object object) {
        this.code = code;
        this.message = message;
        this.object = object;
    }

    public static ResponseVO SUCCESS = new ResponseVO(200, "success", null);

    public static ResponseVO SUCCESS(Object _data) {
        return new ResponseVO(200, "success", _data);
    }


    public static ResponseVO FAIL = new ResponseVO(500, "fail", null);

    public static ResponseVO FAIL(Object object) {
        return new ResponseVO(500, "fail", object);
    }

}
*************************************************************************************************************************************

package com.sinosoft.web.controller.test.EnumTest;


public enum AgeEnum {

    child(10,"儿童"),
    adolescence(20,"青少年"),
    adult(30,"成人"),
    old(40,"大叔");
    private int age;
    private String name;

     AgeEnum(int age,String name){
        this.age = age;
        this.name = name;
    }

    public int getAge(){
         return age;
    }

    public void setAge(int age){
         this.age = age;
    }

    public String getName(){
         return name;
    }
    public void setName(String name){
         this.name = name;
    }

    public static String getName(int age){

        AgeEnum[] values = AgeEnum.values();
        for (AgeEnum ageObj:values) {
            if (age == ageObj.getAge()){
                return ageObj.getName();
            }
        }

        return "未知年龄段";
    }




}
public enum ChannelTypeEnum {
    
    EPCC("EPCC", "1");
    private String code;
    private String name;

    ChannelTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    private static Map<String, ChannelTypeEnum> codeMap;
    private static Map<String, ChannelTypeEnum> nameMap;

    static {
        codeMap = new HashMap<>();
        nameMap = new HashMap<>();
        for (ChannelTypeEnum typeEnum : ChannelTypeEnum.values()) {
            codeMap.put(typeEnum.code, typeEnum);
            nameMap.put(typeEnum.name, typeEnum);
        }
    }
    
    public static String getName(String code) {
        if (StringUtils.isEmpty(code)) {
            return "";
        }
        ChannelTypeEnum typeEnum = codeMap.get(code);
        return typeEnum.getName();
    }

    public static String getCode(String name) {
        if (StringUtils.isEmpty(name)) {
            return "";
        }
        ChannelTypeEnum typeEnum = nameMap.get(name);
        return typeEnum.getCode();
    }


}

最后

以上就是娇气小刺猬为你收集整理的返回值vo定义和枚举类定义的全部内容,希望文章能够帮你解决返回值vo定义和枚举类定义所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部