0
我得到這個異常:java.lang.IllegalStateException:無論BindingResult也不是爲bean名稱 'RegistrationBean' 可以作爲請求屬性平原目標對象
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'RegistrationBean' available as request attribute
這是我的控制器類
@Controller
public class TenantRegistrationController {
@Autowired
private TenantService tenantService;
@Autowired
private UserService userService;
RegistrationBean是從jsp作爲模型屬性傳遞的bean類。
@RequestMapping(value="/registration", method= RequestMethod.POST)
public String addNewTenant(@ModelAttribute("RegistrationBean")RegistrationBean registrationBean,
BindingResult result, Map<String,Object> map)
{
Tenant tenant = new Tenant();
tenant.setTenant_name(registrationBean.getTenantName());
tenant.setTenant_email(registrationBean.getTenantEmail());
tenant.setAddress(registrationBean.getTenantAddress());
// tenant.setReminder_email(Integer.parseInt(registrationBean.getReminderMail()));
tenant.setReminder_email(registrationBean.getReminderMail());
tenant.setThankyou_email(registrationBean.getThankyouMail());
CurrencyFormat cf = new CurrencyFormat();
cf.setCurrencyFormatId(registrationBean.getCurrencyFormatId());
tenant.setTenantCurrencyFormat(cf);
DateFormat df = new DateFormat();
df.setDateFormatId(registrationBean.getDateFormatId());
tenant.setTenantDateFormat(df);
tenant.setRegistration_date(registrationBean.createRegistrationDate());
tenantService.addTenant(tenant);
User user = new User();
user.setName(registrationBean.getUserName());
user.setAddress(registrationBean.getUserAddress());
user.setUser_name(registrationBean.getUserLoginName());
user.setDesignation(registrationBean.getUserDesignation());
user.setPassword(registrationBean.getUserPassword());
user.setEmail(registrationBean.getUserEmail());
user.setContact_number(registrationBean.getUserContactNo());
Role urole=new Role();
urole.setRole_id(1);
user.setUser_role(urole);
userService.addUser(user);
map.put("tenant_name", tenant.getTenant_name());
return "tenant_registration_success";
}
@RequestMapping("/addANewTenant")
public String showAddTenantPage(Map<String, Object> map)
{
/*map.put("item", new Item());
map.put("itemList", itemService.listitems());*/
return "add_tenant_details";
}
}
這是我的JSP文件
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Tanent Registration and Tanent Administrator Registration</title>
<style>
.error {
color: #ff0000;
font-style: italic;
}
</style>
</head>
<body>
我指定命名的 「RegistrationBean」 爲的ModelAttribute
<h3>Tenant Registration</h3>
<form:form method="post" action="/MTInvoiceManagement/tenant/registration.html" modelAttribute="RegistrationBean">
<table align="left">
<tr>
<td>Tenant Name</td>
<td><form:input path="tenantName" type="text" /></td>
<td><form:errors path="tenantName" cssClass="error"></form:errors></td>
</tr>
<tr>
<td>Tenant Email</td>
<td><form:input path="tenantEmail" type="text" /></td>
<td><form:errors path="tenantEmail" cssClass="error"/></td>
</tr>
<tr>
<td>Tenant Address</td>
<td><input name="tenantAddress" type="text" /></td>
<td><form:errors path="tenantAddress" cssClass="error" ></form:errors></td>
</tr>
<tr>
<td>Reminder Mail</td>
<td>
<form:select path="reminderMail">
<form:option value="0" label="No" />
<form:option value="1" label="Yes" />
</form:select>
</td>
<td><form:errors path="reminderMail" cssClass="errors"></form:errors></td>
</tr>
<tr>
<td>Thank You Mail</td>
<td>
<form:select path="thankyouMail">
<form:option value="0" label="No"></form:option>
<form:option value="1" label="Yes"></form:option>
</form:select>
</td>
<td> <form:errors path="thankyouMail" cssClass="errors"></form:errors> </td>
</tr>
<tr>
<td>Date Format</td>
<td>
<form:select path="dateFormatId">
<form:option value="1" label="DD-MM-YY"></form:option>
<form:option value="2" label="MM-DD-YY"></form:option>
<form:option value="3" label="YYYY-MM-DD"></form:option>
</form:select>
</td>
<td><form:errors path="dateFormatId" cssClass="errors"></form:errors></td>
</tr>
<tr>
<td>Currency Format</td>
<td>
<form:select path="currencyFormatId">
<form:option value="1" label="$"></form:option>
<form:option value="2" label="£"></form:option>
<form:option value="3" label="¥"></form:option>
<form:option value="4" label="€"></form:option>
<form:option value="5" label="₨"></form:option>
</form:select>
</td>
<td><form:errors path="currencyFormatId" cssClass="errors" ></form:errors></td>
</tr>
<tr>
<td> <h3> Tanent Administrator Details </h3> </td>
</tr>
<tr>
<td>Tanent Admin Name</td>
<td><form:input path="userName" type="text"/> </td>
<td> <form:errors path ="userName" cssClass="errors"></form:errors> </td>
</tr>
<tr>
<td>Tanent Admin User Login Name</td>
<td><form:input path="userLoginName" type="text"/> </td>
<td> <form:errors path ="userLoginName" cssClass="errors"></form:errors> </td>
</tr>
<tr>
<td>Tanent Admin User Password</td>
<td><form:input path="userPassword" type="password"/> </td>
<td> <form:errors path ="userPassword" cssClass="errors"></form:errors> </td>
</tr>
<tr>
<td>Tanent Admin User Email</td>
<td><form:input path="userEmail" type="text"/> </td>
<td> <form:errors path ="userEmail" cssClass="errors"></form:errors> </td>
</tr>
<tr>
<td>Tanent Admin User Contact No</td>
<td><form:input path="userContactNo" type="text"/> </td>
<td> <form:errors path ="userContactNo" cssClass="errors"></form:errors> </td>
</tr>
<tr>
<td> </td>
<td>
<input name="Submit" type="submit" value="submit" />
</td>
</tr>
</table>
</form:form>
</body>
</html>
豆請大家幫幫我!