SpringBoot接口查询所有的枚举值

在枚举类上添加 @JsonFormat(shape = JsonFormat.Shape.OBJECT) 然后接口返回Enums.values();就可以

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum OperationTypeEnum {
    LOGIN("login", "登录"),
    UPDATE("update", "修改"),
    ACKNOWLEDGE_OUTGOING("outGoing", "确认外送"),
    CANCEL_DELIVERY("cancelDelivery", "取消外送"),
    CHECK("check", "审核"),
    CANCEL_CHECK("cancelCheck", "取消审核"),
    SING_IN("singIn", "签收"),
    CANCEL_SING_IN("cancelSingIn", "撤销签收"),
    RECEIVE("receive", "接收"),
    CANCEL_RECEIVE("cancelReceive", "撤销接收"),
    MAKE("make", "制单"),
    PRINT("print", "打印"),
    ;
    private String code;
    private String type;

    OperationTypeEnum(String code, String type) {
        this.code = code;
        this.type = type;
    }

    public static OperationTypeEnum getType(String code) {
        OperationTypeEnum result = null;
        for (OperationTypeEnum s : values()) {
            if (s.getCode().equals(code)) {
                result = s;
                break;
            }
        }
        return result;
    }
}

接口

@GetMapping("/getAllType")
    public Response<OperationTypeEnum[]> getAllType() {
        return Response.success(OperationTypeEnum.values());
    }

响应结果

{
	"code": 0,
	"msg": "请求成功~",
	"data": [
		{
			"code": "login",
			"type": "登录"
		},
		{
			"code": "update",
			"type": "修改"
		},
		{
			"code": "outGoing",
			"type": "确认外送"
		},
		{
			"code": "cancelDelivery",
			"type": "取消外送"
		},
		{
			"code": "check",
			"type": "审核"
		},
		{
			"code": "cancelCheck",
			"type": "取消审核"
		},
		{
			"code": "singIn",
			"type": "签收"
		},
		{
			"code": "cancelSingIn",
			"type": "撤销签收"
		},
		{
			"code": "receive",
			"type": "接收"
		},
		{
			"code": "cancelReceive",
			"type": "撤销接收"
		},
		{
			"code": "make",
			"type": "制单"
		},
		{
			"code": "print",
			"type": "打印"
		}
	],
	"success": true
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值