我在 localohst: 上得到“welcome”,而不是我的welcome.jsp
这是我的 Controller :
@RestController
public class WelcomeController {
// inject via application.properties
@Value("${welcome.message:test}")
private String message = "Hello World";
@RequestMapping("/")
public String welcome(Map<String, Object> model) {
model.put("message", this.message);
return "welcome";
}
启动应用程序:
public class SpringBootWebApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringBootWebApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootWebApplication.class, args);
}
应用程序属性:
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
最佳答案
您的WelcomeController
是休息 Controller ,使其成为带有@Controller
注释的普通 Controller ,如本示例所示。
https://medium.com/@milansavaliyaz/spring-boot-hello-world-example-with-jsp-view-7ffed2ae931d
关于java - jsp 未在请求的 uri 上呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51880603/