【发布时间】:2023-03-24 11:04:01
【问题描述】:
这是我的控制器代码:
@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
{ 私有静态最终长序列版本UID = 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}";
【问题讨论】:
-
方法怎么调用?
-
listId是整数(即数字)不是字母吗? -
似乎他在不更改 {listid} 参数的情况下调用 url,因此是 numberFormatExc。附:是的,和@Janar 回答的一样
-
@Zeromus 如何克服这个异常请详细告诉我