Announcement Announcement Module
Collapse
No announcement yet.
How do I add errors to my Spring MVC REST Service? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I add errors to my Spring MVC REST Service?

    How can I change/update the following REST call from Spring MVC to return a error if the user did not enter of the the two names I was coding for.. something like a NOT FOUND ?

    Code:
    @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;
        }
Working...
X