【问题标题】:Spring MVC template resolver for JSPJSP 的 Spring MVC 模板解析器
【发布时间】:2016-05-29 08:41:35
【问题描述】:

我实际上使用的是 Spring MVC、Spring Security 和 Thymeleaf。 如何在我的应用程序中添加使用 jsp 的可能性?

我尝试将这些行添加到我的 应用程序.properties

spring.mvc.view.prefix=classpath:/templates/jsp/
spring.mvc.view.suffix=.jsp

我的想法是我希望能够在文件夹中使用 jsp src/main/resources/模板/jsp/ 以及 src/main/resources/templates/thymeleaf/ 中的 thymeleaf html 文件

我的控制器

@Controller
public class HelloJSP {
    @RequestMapping("/jsp")
    public String helloJSP() {
        return "hello";
    }
}

我的 hello.jsp 在文件夹 src/main/ressources/templates/jsp/hello.jsp

我需要在 Spring 安全资源处理程序中的某处注册 jsp 资源吗?

【问题讨论】:

  • 我特指配置“多视图解析器”,但不知道如何不破坏spring boot的自动配置。

标签: jsp spring-mvc


【解决方案1】:

很容易解决

改变

spring.mvc.view.prefix=classpath:/templates/jsp/

进入

spring.mvc.view.prefix=classpath:/templates/

当您想从 jsp 或 thymeleaf 创建视图时,请在此处添加前缀,例如“jsp/my_jsp_page”和“thymeleaf/my_thymeleaf_page”

参考:How to use multiple places in Spring viewresolver?

【讨论】:

  • 其实我也需要两个后缀,但是设置一个参数让我只添加一个后缀。
  • 如果你必须使用两个后缀,我发现this 这不是一个小修复,但也不是很多。让我知道它是否有效。
猜你喜欢
  • 2016-01-30
  • 2015-05-28
  • 1970-01-01
  • 2016-01-27
  • 2017-01-01
  • 2012-04-15
  • 2017-05-10
  • 2016-03-13
  • 2014-05-11
相关资源
最近更新 更多