我正在使用Spring roo,并且在其中一个控制器中,我使用如下字符串设置了模型属性“ error”:
//uiModel.addAttribute("error","Duplicate name for Vendor");
@RequestMapping(method = RequestMethod.POST)
public String create(@Valid Vendor vendor,BindingResult bindingResult,Model uiModel,HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("vendor",vendor);
addDateTimeFormatPatterns(uiModel);
return "vendors/create";
}
try {
vendorService.saveVendor(vendor);
uiModel.asMap().clear();
} catch(Exception e) {
uiModel.addAttribute("vendor",vendor);
uiModel.addAttribute("error","Duplicate name for Vendor");
addDateTimeFormatPatterns(uiModel);
return "vendors/create";
}
return "redirect:/vendors/" + encodeUrlPathSegment(vendor.getId().toString(),httpServletRequest);
}
现在,我的问题是如何在创建页面上显示错误(如果不为null),如下所示.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<jsp:output omit-xml-declaration="yes"/>
<form:create id="fc_domain_Vendor" modelAttribute="vendor" path="/vendors" render="${empty dependencies}" z="MGZPL+gO+CDX6M4iRO/z/qRfnJI=">
<field:input field="name" id="c_domain_Vendor_name" required="true" z="s+3hs8xXpSZ71RoD0ktXy0BnjS0="/>
<field:input field="email" id="c_domain_Vendor_email" validationMessageCode="field_invalid_email" z="+4rIdPGArWhHQlrFG/1N6yrKKno="/>
<field:input field="mobile" id="c_domain_Vendor_mobile" max="16" z="kgM5Z9jJ6xW9BxiPPB4Ipz0TUKg="/>
</form:create>
<form:dependency dependencies="${dependencies}" id="d_domain_Vendor" render="${not empty dependencies}" z="hLv7c7K8OOSRrBJKgKuw9H1+GvA="/>
</div>
提前致谢
最佳答案
原文链接:https://www.f2er.com/spring/531895.html