米折网登录,深圳阳光医院怎么样,异界药皇
springmvc默认无法自动封装枚举类,解决方法如下:
1.枚举类
public enum goodspromoteenum { /** * 0 精品 */ fine("精品",0), /** * 1 限时购 */ limit("限时购",1), /** * 2 特价 */ 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; } }
2.编写自定义处理类,继承converter接口
public class stringtogoodsconverter implements converter<string, goodspromoteenum> { @override public goodspromoteenum convert(string value) { if (stringutils.isblank(value)) { return null; } return goodspromoteenum.get(value); } }
3.在springmvc配置文件里配置
<!--自定义枚举类封装 --> <bean id="conversionservice" class="org.springframework.format.support.formattingconversionservicefactorybean"> <property name="converters"> <set> <bean class="com.tentcoo.zbh.util.stringtogoodsconverter" /> </set> </property> </bean>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论