【问题记录】Springboot项目中templates和static的区别和templates网页如何用后台方式打开

1.开发环境

Idea+maven+Springboot2.0.2.RELEASE+thymeleaf+yml配置文件

2.项目目录

2.遇到的问题1

将Springboot项目部署到Windows服务后,使用ip:端口/index.html的方式无法打开主页.

templates中的网页并不能以这种方式打开.

解决方法:html在templates中建议使用后台请求Controller的方式打开

@Controller
@CrossOrigin
@RequestMapping("/")
public class CommonController {
    @RequestMapping("/index")
    public String toIndex(){
        return "index";
    }
    @RequestMapping("/klgOperateLayer")
    public String toklgOperateLayer(){

        return "klgOperateLayer";
    }
}

将Springboot依赖换成2.x不要再用1.x了,引入thymeleaf依赖,相关配置可以看我的关于Springboot整合thymeleafhttps://blog.csdn.net/qq_33605879/article/details/105277741

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/>
    </parent>
<dependencies>
... ...
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>

2.遇到的问题2

主页引用不到static中的js和css,是因为thymelef配置不对,也有可能是Springboot版本过低,可参考

https://blog.csdn.net/qq_33605879/article/details/105277741配置

然后便可以使用在浏览器输入 ip:端口/index 请求跳转到主页

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值