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 请求跳转到主页