IntelliJ IDEA在使用SpringBoot集成thymeleaf时,将html页面放在webapp/WEB-INF/下报错无法访问

IntelliJ IDEA在使用SpringBoot集成thymeleaf时,将html页面放在webapp/WEB-INF/view下报错无法访问
eclipse可以正常访问,但是IntelliJ IDEA下不可以,通过controller访问页面是直接报如下错误
org.thymeleaf.exceptions.TemplateInputException:
Error resolving template "login", template might not exist or might not be accessible by any of the configured Template Resolvers

解决方法:

在项目pom文件内,build标签下添加如下resource配置

    <build>
        <resources>
            <resource>
                <directory>src/main/webapp</directory>
                <!--注意此次必须要放在此目录下才能被访问到 -->
                <targetPath>META-INF/resources</targetPath>
                <includes>
                    <include>**/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>
    </build>

配置文件prefix指定路径

spring.thymeleaf.prefix=/WEB-INF/view/
spring.thymeleaf.mode=HTML5
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
spring.thymeleaf.check-template=true

controller内返回页面名时前面不要带 /

    @GetMapping(value = {"/login"})
    public String login(Model model) {
        model.addAttribute("host", "127.0.0.1");
        return "login";
    }

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值