JSP未在请求的URI上呈现

时间:2018-08-16 15:28:16

标签: java spring spring-mvc jsp spring-boot

我对localohst表示欢迎,而不是我的welcome.jsp

这是我的控制者:

 @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";
    }

StartupApplication:

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);
    }

application.properties:

spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix: .jsp

1 个答案:

答案 0 :(得分:2)

您的WelcomeController是rest控制器,使其成为带有@Controller注释的普通控制器,如本示例所示。 https://medium.com/@milansavaliyaz/spring-boot-hello-world-example-with-jsp-view-7ffed2ae931d