ITeye博客

当表单提交时将空字符串转换为null

hepx · 2015-09-29 11:43 · spring · 开源软件 · Markdown

SpringMVC解决方案:

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}

使用场景:比如做多条件查询时,hibernate的criteria需要过滤掉Form提交的空字符字段。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。