目前,我的控制器中有以下方法,它接受用户表单输入并将其传递给sql查询以返回匹配列表。
@RequestMapping(value = "/resultsPage", method = RequestMethod.GET)
public ModelAndView newSearch(HttpServletRequest request)
{
int id = Integer.parseInt(request.getParameter("id"));
List<newobject> listSearch = newDAO.loadSearch(id);
ModelAndView model = new ModelAndView("results");
model.addObject("listSearch", listSearch);
return model;
}
我已经在newobject中的id文件中添加了@notnull,但是我不确定如何修改上面的方法来检查用户输入(或未输入)的变量。
我也不确定如何在html页面上显示错误。我的现有代码如下:
<form method="get" th:action="@{/results}">
<input id="search" name="id" class="search" placeholder="Ref..."
type="text" maxlength="10" title="Numerical values only" />
<button type="submit" method="post" style="display:none;" id="search">Search</button>
</form>
谁能给我一些建议,我将如何添加验证,因为我只是得到错误的每件事,我尝试。
暂无答案!
目前还没有任何答案,快来回答吧!