2017-11-06 4 views
0

먼저 데이터베이스에서 테이블로 값을 전달합니다. 첫 번째 열에서 컨트롤러에서 ID를 삭제하는 함수를 전달하는 폼을 만들고 싶습니다.컨트롤러에 ID 전달

<tr th:each="blg: ${all}" th:object="${blg}" > 
    <td> 
    <form th:action="@{/delete}" th:object= "${blg}" method="post"> 
    <input type="text" th:field="${blg.id}"/> 
    <button type="submit">Delete</button> 
    </form> 
    </td> 
    <td th:text="*{title}"> title </td>  
    <td th:text="*{content}"> title </td> 
    <td th:text="*{category}"> title </td> 
    <td th:text="*{signature}"> title </td> 
</tr> 

컨트롤러 :

java.lang.IllegalStateException :

@GetMapping("/show") 
public String show(Model model){ 
    List<Blog> all = br.findAll(); 
    model.addAttribute("all",all); 
    return "show"; 
} 

@RequestMapping(value="/delete", method=RequestMethod.POST) 
    public String deletePost(@RequestParam Long id){   
     br.delete(id);   
     return "redirect:/show"; 
    } 

가 thymeleaf 엔진은이 오류 occcurs 같은 객체를 매핑하지 않습니다 BindingResult이나 콩 이름에 대한 일반 대상 객체 어느 ' 요청 속성으로 'blg'를 사용할 수 있습니다.

이 경우 올바른 양식을 만드는 방법은 무엇입니까? 아래 그림과 같이

답변

0

업데이트 HTML 코드 :

<tr th:each="blg: ${all}" > 
    <td> 
     <form th:action="@{|/delete/${blg.id}|}" method="post"> 
      <button type="submit">Delete</button> 
     </form> 
    </td> 
    <td th:text="${blg.title}"> title </td>  
    <td th:text="${blg.content}"> title </td> 
    <td th:text="${blg.category}"> title </td> 
    <td th:text="${blg.signature}"> title </td> 
</tr> 

더 나은이 삭제 작업을위한 HTTP 방식 DELETE를 사용합니다.

th:object이 (가) blg 속성의 요청 ​​속성을 조사하려했기 때문입니다. 그러나 blg은 반복의 결과입니다.