如何使用ID检查HTTP GET方法的响应

时间:2017-09-28 07:16:18

标签: spring hibernate rest

这是我的控制器代码:

@RequestMapping(value = RestURIConstants.GET_APP_MENU_LIST, method = RequestMethod.GET)
public @ResponseBody ComListMaster getCommonMasterByMasterId(@PathVariable("listid") Integer listId)
{
    ComListMaster commonMaster = commonService.getCommonMasterList(listId);
    logger.debug("Calling master list");
    return commonMaster;
}

上面的代码给我例外:

引起:java.lang.NumberFormatException:对于输入字符串:“{listid}”

请告诉我如何获得上述代码的GET响应。

提前致谢。 这是ComListMaster

public class ComListMaster extends BaseModel implements java.io.Serializable

{     private static final long serialVersionUID = 5408136749548491686L;

@Id
@Column(name = "LIST_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer listId;

@Column(name = "LIST_DESC")
private String description;

@Column(name = "LIST_VALUE")
private String value;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "comListMaster")
private Set<ComListDetails> comListDetails = new HashSet<ComListDetails>();

public Integer getListId()
{
    return listId;
}

public void setListId(Integer listId)
{
    this.listId = listId;
}

public String getDescription()
{
    return description;
}

public void setDescription(String description)
{
    this.description = description;
}

public String getValue()
{
    return value;
}

public void setValue(String value)
{
    this.value = value;
}

public Set<ComListDetails> getComListDetails()
{
    return comListDetails;
}

public void setComClientAddresses(Set<ComListDetails> comListDetails)
{
    this.comListDetails = comListDetails;
}

@Override
public String toString()
{
    return "ComListMaster [listId=" + listId + ", description=" + description + ", value=" + value
            + ", comListDetails=" + comListDetails + "]";
}

}

我的例外是:java.lang.NumberFormatException:对于输入字符串:“{listid}”

API:public static final String GET_APP_MENU_LIST =“/ api / app / common / master / {listid}”;

2 个答案:

答案 0 :(得分:0)

你可以删除(“listid”) - 它不是强制性的,然后它不会java.lang.NumberFormatException:对于输入字符串:“{}”。

@RequestMapping(value = "/{listId}", method = RequestMethod.GET)
public @ResponseBody ComListMaster getCommonMasterByMasterId(@PathVariable Integer listId)
{
    ComListMaster commonMaster = commonService.getCommonMasterList(listId);
    logger.debug("Calling master list");
    return commonMaster;
}

答案 1 :(得分:0)

您发布的代码是正确的。

该错误似乎表明您正在尝试转到/api/app/common/master/{listid}网址。相反,您应该使用真实ID替换{listid},例如/api/app/common/master/1