如果用户没有输入我正在编码的两个名称,我如何从 Spring MVC 更改/更新以下 REST 调用以返回错误..类似于 NOT FOUND ?
@RequestMapping(value = "/{name}", method = RequestMethod.GET)
@ResponseBody
public User getName(@PathVariable String name, ModelMap model)
{
logger.debug("I am in the controller and got user name: " + name);
/*
Simulate a successful lookup for 2 users, this is where your real lookup code would go
*/
if ("name2".equals(name))
{
return new User("real name 2", name);
}
if ("name1".equals(name))
{
return new User("real name 1", name);
}
return null;
}