why this Model thing works on @Controller but doesnt work on @RestController
when i try
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@Controller
public class ArticleController {
`@GetMapping("/articles")`
`public String getArticles(Model model) {`
`List<Article> articles = articleService.findAllArticles();`
`model.addAttribute("articles", articles);`
`return "articleList";`
`}`
`@GetMapping("/article/{id}")`
`public String getArticleById(@PathVariable Long id, Model model) {`
`Article article = articleService.findArticleById(id);`
`model.addAttribute("article", article);`
`return "articleDetail";`
}`
}
it works, but exact same code with @RestController intead of @Controller
don’t work
hamdam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.