請問各位前輩,
我以Spring框架要在網頁顯示資料表,
但卻一直跳出
Neither BindingResult nor plain target object for bean name 'contact' available as request attribute
以及出現下列訊息:
指說第75行有問題,
但實在不理解,所以想請各位指點小弟
這是我的JSP:
<form:select path="pageList" id="pageList" onchange="changePage(this.value)">
<form:option value=""> --SELECT--</form:option>
<form:options items="${pageList}"></form:options>
</form:select>
<form:form method="POST" action="listContactByPage" commandName="contact">
<form:input path="currentPage" id="currentPage" name="currentPage" value="${currentPage}"/>
</form:form>
這是我的Controller :
@RequestMapping(value="/listContactByPage", method = RequestMethod.POST)
//列出資料庫所有資料 (主頁)
public String listContactByPage(@ModelAttribute("contact") Contact contact, Model model, HttpServletRequest request) {
// public String listContactByPage(@ModelAttribute("contact") Contact contact, BindingResult result, Model model){
// public String listContactByPage(@RequestParam("currentPage") String currentPageFromPage, Model model, HttpServletRequest request) {
int currentPage = 0;
if(contact.getCurrentPage() != null){
currentPage = Integer.parseInt(contact.getCurrentPage());
System.out.println("contact.getCurrentPage():::" + contact.getCurrentPage());
}
System.out.println("currentPage:::" + currentPage);
List<Contact> listContact = contactDAO.list(); //取得全部資料
List<Contact> currentList = new ArrayList<Contact>(); //取得currentPage的資料
//取得currentPage的資料
for(int i = currentPage*10-10; i<currentPage*10; i++){
currentList.add(listContact.get(i));
}
//頁面上列出currentPage的資料
model.addAttribute("listContact", currentList);
// model.addObject("listContact", currentList);
return "home";
}
這是我的DAO :
煩請指導!