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 trialvikas Rai
9,703 PointsUsing @PathVariable to Create a Dynamic Detail Page
When I am using Path variable annotation I am getting this error There was an unexpected error (type=Internal Server Error, status=500). Exception evaluating SpringEL expression: "gif.name" (template: "gif-details" - line 13, col 12)
BELOW IS MY CODE
package com.teamtreehouse.giflib.controller;
import com.teamtreehouse.giflib.data.GifRepository; import com.teamtreehouse.giflib.model.Gif; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;
import java.time.LocalDate;
@Controller //Due to this annotation spring detect this class as controller class public class GifController {
@Autowired
private GifRepository gifRepository;
@RequestMapping("/gif/{nam}")
public String gifDetails(@PathVariable String nam, ModelMap modelMap){
Gif gif= gifRepository.findByName(nam);
modelMap.put("gif", gif);
return "gif-details";
}
}
1 Answer
Daniel Phillips
26,940 PointsI don't see anything wrong with what you shared* You might look at your gif-details.html template.
*by the way, when sharing code, use the following format for Markdown.
Code: Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks.
vikas Rai
9,703 Pointsvikas Rai
9,703 Pointspackage com.teamtreehouse.giflib.model;
import java.time.LocalDate;
public class Gif {
}