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 trialUnsubscribed User
48,988 Pointscapture 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
4,964 PointsThe 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
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey 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.
Unsubscribed User
48,988 PointsYes thanks Rob Bridge, it worked but "don't worry about them" honestly makes no sense to me !?
Jason Anders
Treehouse Moderator 145,860 PointsYes, definitely needs to be reworded. Threw me for a loop too.
Thomas Salai
4,964 PointsWhat 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