【发布时间】:2015-11-15 21:38:54
【问题描述】:
大家好,我正在尝试运行一个简单的 springboot 应用程序。并尝试查看基本的 html,但无法呈现页面。我只能在浏览器上看到字符串,但看不到实际的 html 内容。请告诉我我做错了什么。
TestController.java:
@Controller
public class TestController {
@RequestMapping(value="/person")
@ResponseBody
public String intro(){
System.out.println("HH");
return "index";
}
}
MainApplication.java:
@SpringBootApplication
@ComponentScan(basePackages = "pathToMyControllerFolder")
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
在 spring 文档中提到的 /rsesources/template 文件夹中创建了 index.html: index.html:
<!DOCTYPE html>
<head lang="en">
<title>Spring Framework Guru</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Hello</h1>
<h2>Fellow Spring Framework Gurus!!!</h2>
</body>
</html>
但我无法查看 html 内容,而是查看字符串索引。之前有 whitePage 标签错误并通过添加 @ComponentScan 来修复它,但现在只显示索引而不是实际的 html 内容。
当我检查控制台上的日志信息时,我注意到了这一点:
2015-11-15 13:22:51.442 INFO 11460 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2015-11-15 13:22:51.442 INFO 11460 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
【问题讨论】:
标签: java spring-mvc spring-boot