如何在spring控制器中绑定来自jsp的对象

时间:2014-06-05 05:37:50

标签: java spring hibernate annotations

<c:forEach items="${assetList}" var="ast">
  <tr>
    <td><a href="assets-vehicle-profile/${ast}">${ast.id}</a></td>
    <td>${ast.make}</td>
    <td>${ast.model}</td>
  </tr>
</c:forEach>

控制器逻辑:

@RequestMapping(value = "/assets-details", method = RequestMethod.GET)
   public String assetsDisplay(ModelMap map) {
    return new ModelAndView("assets- details","assetsList",assetManager.getAllAssets())
}

对于上述请求(assets-details),它工作正常,它显示资产表中的所有记录

@RequestMapping("/assets-vehicle-profile/{ast}")
public ModelAndView deleteIssue(@PathVariable("ast") AssetEntity asset ) {

    return new ModelAndView("assets-vehicle-profile","model",asset);
}

我的要求是当用户点击(assets-vehicle-profile)asset-id时,我想将属于该资产id的对象发送给控制器,以显示其他(资产 - 车辆 - 配置文件)jsp中的更多信息

请求:

http://localhost:8080/infra/assets-vehicle-profile/com.leadwinner.infra.entity.AssetEntity@1e5addc

错误:

java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.leadwinner.infra.entity.AssetEntity]: no matching editors or conversion strategy found

1 个答案:

答案 0 :(得分:1)

所以你的方法

public ModelAndView deleteIssue(@PathVariable("ast") AssetEntity asset ) {

期待AssetEntity但当然JSP只发送一个字符串,所以将其更改为

public ModelAndView deleteIssue(@PathVariable("ast") String assetId ) {

     // look up asset from DB ?

}