【发布时间】:2017-03-29 12:03:40
【问题描述】:
这是一个在 Spring 网站上在线下载的 Spring Initialzr 项目。我正在使用普通的@Controller 并返回一个字符串,它应该返回视图名称。我在位置src/main/resources/templates/ 中有dog.html。
控制器和 html 文件发布在下面。
下面是dog.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />`
</head>
<body>
<p> ggg</p>
<p th:text="'Hello, ' + ${dogBreed.breedName} + '!'" />
</body>
</html>
ViewController 下面
@Controller
@RequestMapping("/Disney")
public class ViewController {
@Autowired
BreedService breedService;
@RequestMapping(value = "/{breedName}")
public String getDogsbyBreedName(@PathVariable("breedName") String breedName, Model model) {
//call a method which returns the Object Breed.
// store this returned Object "breed" and return it as an html view to display as Graphical content.
BreedMaster breed = breedService.getAllDogsByBreedName(breedName);
model.addAttribute("dogBreed",breed);
return "dog";
}
@RequestMapping(value = "/viewtest")
public String sampleTest(){
return "sample";
}
}
下面的sample.html
<!DOCTYPE HTML>
<html>
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p> sample html</p>
</body>
</html>
breedService.getAllDogsByBreedName(breedName) 方法按品种名称返回狗列表,我想将其发送到 HTML dog.html。但请注意,即使对于 url /viewtest,它也不会重新发送 sample.html 抛出错误。这意味着我无法达到dog.html 和sample.html 并且从未更改过任何springboot 自动配置。非常需要帮助,我认为这是一个愚蠢的错误,请任何人指出,谢谢。
我在调用/viewtest 时收到的错误消息如下:
我在调用/{breedName} 时收到的错误消息如下:
请注意,重新输入的字符串“dog”与输入的“/{breedName}”不同,后者是“Labrador”
【问题讨论】:
标签: java html spring-mvc spring-boot thymeleaf