几种常用的枚举
一、直接写成员
public enum EnumResultType { ex,notMatch,success,busy }
成员取出是用这种,值为下标
EnumResultType.枚举成员名称.ordinal()
二、K-V的枚举
package com.kaize.admin.wx; import lombok.Getter; import lombok.Setter; /** * @author jianhan * @date 2022/11/18 14:03 * @description */ public enum MessageEnum { /** * 待审批提醒 */ APPROVAL_WAIT("10", "您有一条新的请假申请待审核"), /** * 催办提醒 */ APPROVAL_URGED("20", "{username}同学的请假申请还未处理,请及时对内容进行审核。"), /** * 审批成功结果通知提醒 */ APPROVAL_SUCCESS("30", "您有一条新的请假审核成功结果通知"), /** * 审批失败结果通知提醒 */ APPROVAL_FAIL("40", "您有一条新的请假审核失败结果通知"), /** * 抄送通知提醒 */ APPROVAL_SEND("50", "您有一条新的抄送通知"), /** * 进校门抄送通知提醒 */ PEOPLE_IN_ACCESS("60","家长你好,您的孩子已经进入校园"), /** * 出校门抄送通知提醒 */ PEOPLE_OUT_ACCESS("70","家长你好,您的孩子已经离开校园"), /** * 请假审核回推通知提醒-通过 */ APPROVAL_BACK_SEND("80", "您有一条新的请假审核通过通知,{username}通过"), /** * 请假审核回推通知提醒-驳回 */ APPROVAL_BACK_FAIL("90", "您有一条新的请假审核驳回通知,{username}驳回"); @Getter @Setter private String code; @Getter @Setter private String value; MessageEnum(String code, String value) { this.code = code; this.value = value; } public static MessageEnum getValue(String code) { for (MessageEnum value : values()) { if (value.getCode().equals(code)) { return value; } } return null; } }
用法
/** * @Description: 组装消息 * @Param: leaveModel approvalModel params * @return: json * @Author: jianhan * @Date: 2022-11-18 14:58:34 **/ public static Template getMessage(LeaveModel leaveModel, ApprovalModel approvalModel, String type, Map<String, Object> params) { Template template = new Template(); String content = MessageEnum.getValue(type).getValue(); if (params != null) { for (Map.Entry<String, Object> entry : params.entrySet()) { if (content.contains("{" + entry.getKey() + "}")) { content = content.replace("{" + entry.getKey() + "}", entry.getValue().toString()); } } } template.setFirst(content); if (leaveModel != null) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String startTime = simpleDateFormat.format(leaveModel.getStartTime()); String endTime = simpleDateFormat.format(leaveModel.getEndTime()); template.setKeyword1(leaveModel.getName()); template.setKeyword2("学生请假"); template.setKeyword3(startTime + "至" + endTime); template.setKeyword4(leaveModel.getRemarks()); } if (approvalModel != null) { template.setRemark(approvalModel.getRemarks()); } return template; }
标签:请假,String,Enum,value,枚举,template,APPROVAL,leaveModel From: https://www.cnblogs.com/SjhCode/p/17144047.html