0
votes

Here is my controller code:

@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;
}

Above code give me the exception:

Caused by: java.lang.NumberFormatException: For input string: "{listid}"

Please tell me how to get GET response of above code.

Thanks in advance. here is 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 + "]";
}

}

My exception is: java.lang.NumberFormatException: For input string: "{listid}"

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

2
how do you call the method?Zeromus
Is listId an integer (i-e a number) not a letter ?akuma8
seems like hes calling the url without changing the {listid} parameter hence the numberFormatExc. P.s. yep same thing as @Janar answeredZeromus
@Zeromus How to overcome this Exception please tell me in detailAnup Sonkusare

2 Answers

0
votes

You can remove ("listid")-its not mandatory , then it wont java.lang.NumberFormatException: For input string: "{}".

@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;
}
0
votes

The code you posted is correct.

The error seems to indicate you are trying to go to the /api/app/common/master/{listid} url. Instead you should substitute the {listid} with a real id, for example /api/app/common/master/1