Thymleaf:请求方法' POST'不支持

时间:2016-05-13 15:45:39

标签: java spring-mvc thymeleaf

考虑我有以下表格,我将两个参数_idpoID发送给控制器:

 <form style='float:left; padding:5px; height:0px' th:object="${plant}"  th:method="post" th:action="@{/dashboard/DeliverPlant/{_id}(_id=${plant._id})/{po_id}(po_id=${plant.poID})}">
                        <button class="btn btn-default btn-xs" type="submit">Verify Plant Delivery</button>
                   </form>

在控制器中我有以下形式:

 @RequestMapping(method=POST, path="DeliverPlant/{_id}/{po_id}")
     public String DeliverPlant(Model model,@PathVariable("_id") String id,@PathVariable("po_id") String po_id) throws Exception {                  
            Long Id=    Long.parseLong(id);
         System.out.println("po_id is..................."+po_id+ "_id is:   "+id);


            return "dashboard/orders/ShowPOs";
      }

当我发送请求时,没有内部错误,但它抱怨

There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported

似乎无法识别方法。 那我怎么解决呢?

更新

我也试过这个

<form style='float:left; padding:5px; height:0px' th:object="${plant}"  th:method="post" th:action="@{'/dashboard/DeliverPlant/'+{_id}(_id=${plant._id})+'/'+{po_id}(po_id=${plant.poID})}">
                        <button class="btn btn-default btn-xs" type="submit">Verify Plant Delivery</button>
                   </form>

2 个答案:

答案 0 :(得分:0)

尝试

method="POST"

而不是

th:method="POST"

此外,在您的Controller类中尝试

@RequestMapping(method=RequestMethod.POST

其中RequestMethod是 org.springframework.web.bind.annotation.RequestMethod

答案 1 :(得分:0)

你在modelAndView.addobject“po”,“plant”,“??”中返回控制器。

您在返回页面中选择对象值(选择页面)。

“_ id”&lt; - ??? ... 反正

编辑路径

th:action="@{/dashboard/deliver/plant/__${??.id}__/__${plant.id}__/__${po.id}__ }"

编辑控制器

@RequestMapping(method = RequestMethod.POST, value ="/deliver/plant/{??.id}/{plant.id}/{po.id}")
public String DeliverPlant(@PathVariable("??.id") int id, @PathVariable("po.id") int poId, @PathVariable("plant.id") int plantId)  {                  

     return "dashboard/orders/ShowPOs"; // <-- break point. 
}

您尝试调试。

见价值。