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 Spring Basics Modeling, Storing, and Presenting Data Capture a URI Parameter

capture a URI Parameter but no suitable constructor found for Contact(int).....

stuck in the mud, should i go with @autowired ? and @PathVariable ? Nothing worked....

com/teamtreehouse/contactmgr/controller/ContactController.java
package com.teamtreehouse.contactmgr.controller;
import com.teamtreehouse.contactmgr.model.Contact;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.ui.ModelMap;

@Controller
public class ContactController {
    @RequestMapping("/")
    public String home() {
      return "index";
    }

    @RequestMapping("/contact/{id}")
    public String contact(@PathVariable int id, ModelMap modelMap) {
      Contact c = new Contact(id);
      modelMap.put("contact",c);
      return "contact_detail";
    }
}

4 Answers

Thomas Salai
Thomas Salai
4,964 Points

The solution is...

@RequestMapping("/contact/{id}")
public String contact(@PathVariable int id,ModelMap modelMap) {
  Contact c = new Contact(id,"firstName","lastName","email");
  modelMap.put("contact",c);
  return "contact_detail";
}
Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey Jens, you are super close. Just remember when creating a new contact variable that it has one than one parameters in the construction, you passed id in just fine, just be sure to include the needed string as well. I believe it takes 3, but check in the contact.java file to make sure.

Yes thanks Rob Bridge, it worked but "don't worry about them" honestly makes no sense to me !?

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Yes, definitely needs to be reworded. Threw me for a loop too. :unamused:

Thomas Salai
Thomas Salai
4,964 Points

What is the solution? I did not get yet..

package com.teamtreehouse.contactmgr.controller;

import com.teamtreehouse.contactmgr.model.Contact;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.ui.ModelMap;

@Controller
public class ContactController {
    @RequestMapping("/")
    public String home() {
      return "index";
    }

    @RequestMapping("/contact/{id}")
    public String contact(@PathVariable int id,ModelMap modelMap) {
      Contact c = new Contact(id);
      modelMap.put("contact",c);
      return "contact_detail";
    }
}

I dont know what to change in contact.java file.

Regards,

Thomas