javascript
android 枚举类型比较大小写,Spring 3.0 MVC绑定枚举区分大小写
如果我有一個(gè)像這樣的Spring控制器的RequestMapping ...
@RequestMapping(method = RequestMethod.GET, value = "{product}")
public ModelAndView getPage(@PathVariable Product product)產(chǎn)品是一個(gè)枚舉。例如。 Product.Home
當(dāng)我請(qǐng)求該頁面時(shí),mysite.com/home
我明白了
Unable to convert value "home" from type 'java.lang.String' to type 'domain.model.product.Product'; nested exception is java.lang.IllegalArgumentException: No enum const class domain.model.product.Product.home有沒有辦法讓枚舉類型轉(zhuǎn)換器了解小寫的home實(shí)際上是Home?
我想保持url不區(qū)分大小寫,并且我的Java枚舉用標(biāo)準(zhǔn)大寫字母。
謝謝
解
public class ProductEnumConverter extends PropertyEditorSupport
{
@Override public void setAsText(final String text) throws IllegalArgumentException
{
setValue(Product.valueOf(WordUtils.capitalizeFully(text.trim())));
}
}注冊(cè)它
添加到需要特殊轉(zhuǎn)換的控制器
@InitBinder
public void initBinder(WebDataBinder binder)
{
binder.registerCustomEditor(Product.class, new ProductEnumConverter());
}
總結(jié)
以上是生活随笔為你收集整理的android 枚举类型比较大小写,Spring 3.0 MVC绑定枚举区分大小写的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言 葬礼分号,其实从C语言用分号结尾
- 下一篇: 电脑显示器有胶点(显示器有胶带粘过的痕迹