Controllerにformの情報が渡されなくnullなので解決したいです。
Form
1public class SearchForm { 2 private Date datefrom; 3 private Date dateto; 4 5 public Date getDatefrom() { 6 return datefrom; 7 } 8 public void setDatefrom(Date datefrom) { 9 this.datefrom = datefrom; 10 } 11 public Date getDateto() { 12 return dateto; 13 } 14 public void setDateto(Date dateto) { 15 this.dateto = dateto; 16 } 17} 18 19
HTML
1<form method="post" action="/searchresult" 2 th:object="${searchForm}"> 3 <table border="1"> 4 <tr> 5 <th>日付</th> 6 </tr> 7 <tr> 8 <td>From<input type="text" id="datefrom" name="datefrom"> 9 ~To<input type="text" id="dateto" name="dateto"> 10 </td> 11 </tr> 12 </table> 13 <input type="submit" id='search' value="検索"> 14 </form>
Controller
1@PostMapping("/searchresult") 2 public ModelAndView searchresult(@ModelAttribute("searchForm") SearchForm form,BindingResult result, 3 ModelAndView mav,Search entity){ 4if(result.hasErrors()) { 5 return mav; 6} 7 mav.setViewName("searchresult"); 8 mav.addObject("searchForm", new SearchForm()); 9 Iterable<Kakeibo> list = service.searchAll(form); 10 mav.addObject("datalist", list); 11 return mav; 12 }
回答2件
あなたの回答
tips
プレビュー