从零开始搭建springboot web项目(一)
2018-03-16 本文已影响0人
6bc9f71c8f0c

新建项目
本项目采用idea搭建

指定groupID和ArtifactID,由于是WEB项目,我们将packing设定为war

选择springboot版本号,这里选择1.5.10,添加web和thymeleaf依赖,后续依赖,我们手动在pom文件中添加

新建一些必要的包和web.xml
在main下面新建webapp>>WEB-INF>>web.xml

国际惯例“hello world”
在application.properties文件中配置thymeleaf的一些信息
############################################################
#
# thymeleaf
#
############################################################
spring.thymeleaf.prefix=/WEB-INF/html
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
注意mode为LEGACYHTML5可以规避html中一些不规范的标签还需要再pom中引入额外的nekohtml包,如下
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
我们新建一个HelloController

在WEB-INF下面新建html包,包下新建一个index.html,由于代码比较简单,这里只截图显示

接下来配置tomcat服务器,idea配法如下


然后点运行即可,运行结果

代码已经上传到了github 点击跳转