springMVC默认无法自动封装枚举类,解决方法如下:枚举类public enum GoodsPromoteEnum { fine("精品",0), limit("限时购",1), cheap("特价",2);
springMVC默认无法自动封装枚举类,解决方法如下:
枚举类
public enum GoodsPromoteEnum { fine("精品",0), limit("限时购",1), cheap("特价",2); private String value; private int index; private GoodsPromoteEnum(String value, int index) { this.value = value; this.index = index; } public static GoodsPromoteEnum get(String value){ for (GoodsPromoteEnum p : GoodsPromoteEnum.values()) { if (p.getValue().equals(value)) { return p; } } return null; } public static GoodsPromoteEnum get(int index){ for (GoodsPromoteEnum p : GoodsPromoteEnum.values()) { if (p.getIndex() == index) { return p; } } return null; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } public int getIndex() { return index; } public void setIndex(int index) { this.index = index; }}
--结束END--
本文标题: 详解SpringMVC 自动封装枚举类的方法
本文链接: https://lsjlt.com/news/226745.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0