弹簧靴胸腺不加载html
我有一个Java和Maven项目,其中我有以下控制器(src/main/java/com/example/romannumerals/controller/romannumeralController):
@RestController
public class RomanNumeralController {
@GetMapping("/roman-numerals/{number}")
public String RomanNumeral(@PathVariable int number){
return RomanNumeralsService.numberToNumeral(number);
}
@GetMapping("/roman-numerals")
public String RomanNumeral() {
return "roman-numeral";
}
}
i SOME HTML(src/main/resource/resources/resources/spemplates/roman-numeral.html)看起来像这样:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>From Numbers to Roman Numerals</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Roman Numerals
</body>
</html>
我希望当我在没有参数的控制器上调用该方法时会显示此HTML。取而代之的是,我将字符串“罗马 - 名字”印在屏幕上。我做错了吗?我以为百里叶会认识到我想显示带有该名称的HTML页面,而不是显示的字符串。
I have a Java and Maven project in which I have the following controller (src/main/java/com/example/romannumerals/controller/RomanNumeralController):
@RestController
public class RomanNumeralController {
@GetMapping("/roman-numerals/{number}")
public String RomanNumeral(@PathVariable int number){
return RomanNumeralsService.numberToNumeral(number);
}
@GetMapping("/roman-numerals")
public String RomanNumeral() {
return "roman-numeral";
}
}
I some HTML (src/main/resources/templates/roman-numeral.html) that looks like this:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>From Numbers to Roman Numerals</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Roman Numerals
</body>
</html>
I expected this HTML to be displayed when I called the method on the controller that has no parameter. Instead, I get the string "roman-numeral" printed to the screen. Am I doing something wrong? I thought Thymeleaf would recognise that I want to display the HTML page with that name instead of the string being displayed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用@controller替换@RestController。 @RestController将使返回的对象成为HTTP响应主体。
Replace @RestController with @Controller. @RestController will make the returned object the HTTP response body.
将@restController更改为@controller为我工作!
Changing @RestController to @Controller worked for me!