Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

add-a-controller-method-for-saving-a-new-contact

In this challenge (https://teamtreehouse.com/library/spring-with-hibernate/getting-started-with-crud-in-spring-hibernate/add-a-controller-method-for-saving-a-new-contact), below is what I have submitted for the method, but it's telling me: @RequestMapping annotation doesn't specify correct value for the `path` (or `value`) element


  @RequestMapping(value = "/contacts", method = RequestMethod.POST)
  public String add(Contact contact) {
    // TODO: Save the Contact object
    contactService.save(contact);  
    return "redirect:/contacts/" + contact.getId();  
  }

Please help me figure out what is wrong.

1 Answer

Figured it out...I was missing a @RequestParam annotation as in below:

  public String add(@RequestParam(name="contact") Contact contact) { 

For anyone who was struggling with this, don't forget to import @RequestParam:

org.springframework.web.bind.annotation.RequestParam;