在我的应用程序中,我有一个表单,用户可以在其中插入或不插入值;因此,这些值是可选的(最终,用户无法插入值并在 SQL 端获取 a select *
)。
为此,我使用了 Spring JdbcTemplates 和语法:
(? is null or name_variable = ?)
经过测试,这适用于后端。
问题是,使用这种语法,如果我想允许用户不在表单中插入值 x,我必须将一个null
值传递给控制器(使用具有此语法的 DAO 方法)。如果我有作为输入类型,在我的表单中,text
我该如何执行?
使用此代码解决:
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句