目前Spring 官方提供了web的方式进行快速构建,可访问地址:https://start.spring.io/ 地址,那这里为了手把手教大家,就自己动手、丰衣足食了,有兴趣的小伙伴可以自己动动小手指,自己DIY
使用Eclipse 创建maven项目
项目名称:spring-boot-infrastructure-projects
打开eclipse , File > New > Maven Project
New Maven project
选择Next >, 选择Artifact Id : maven-archetype-quickstart
maven-archetype-quickstart
选择Next >, 输入项目信息
2018-9-1 12-46-33.png
选择Finish完成
spring-boot-infrastructure-projects
创建源文件:
src/main/resource
src/test/resource
Eclipse > 文件 > 新建 > 新建 Source Folder
src/mian/resources
至此,一个简单的Maven项目构建完成,截图如下
Maven Project Build Finished
配置Spring Boot + Spring MVC + Thymleaf Hello World 环境pom.xml文件
4.0.0 com.lab spring-boot-infrastructure-projects0.0.1-SNAPSHOT jar spring-boot-infrastructure-projects http://maven.apache.org UTF-8 org.springframework.boot spring-boot-starterorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-thymeleaforg.thymeleaf.extras thymeleaf-extras-springsecurity4io.spring.platform platform-bomCairo-RELEASE pom import spring-boot-infrastructure-projects org.apache.maven.plugins maven-compiler-plugin1.8 1.8 UTF-8
配置文件: application.yml
server: port: 8080 servlet: context-path: / spring: http: encoding: charset: UTF-8 force: true enabled: true messages: encoding: UTF-8 thymeleaf: server: port: 8080 servlet: context-path: / spring: http: encoding: charset: UTF-8 force: true enabled: true messages: encoding: UTF-8 thymeleaf: # Prefix that gets prepended to view names when building a URL. prefix: classpath:/templates/ # Suffix that gets appended to view names when building a URL. suffix: .html # Template encoding. encoding: UTF-8 # Enable template caching. cache: false # Enable MVC Thymeleaf view resolution. enabled: true # Template mode to be applied to templates. See also StandardTemplateModeHandlers. mode: HTML # Check that the templates location exists. check-template-location: true servlet: # Content-Type value. content-type: text/html
配置Spring MVC, WebMVCConfig .java
package com.lab.spring.boot.infrastructure.projects.config.web;import org.springframework.beans.factory.annotation.Configurable;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configurablepublic class WebMVCConfig implements WebMvcConfigurer {
}首页Hello World 页面配置PortalController.java
package com.lab.spring.boot.infrastructure.projects.component.portal.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;@Controllerpublic class PortalController {
@RequestMapping(value="/",method= RequestMethod.GET)
public String index() { return "index";
}
}最终项目目录结构如下:
Finished
作者:数据服务
链接:https://www.jianshu.com/p/97e8740488f1



