栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > SpringBoot

Spring Boot 基础框架

SpringBoot 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Boot 基础框架

搭建基本环境

目前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-projects
    0.0.1-SNAPSHOT
    jar

    spring-boot-infrastructure-projects
    http://maven.apache.org

    
        UTF-8
    

    
    
        
        
            org.springframework.boot
            spring-boot-starter
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
         
        
            org.thymeleaf.extras
            thymeleaf-extras-springsecurity4
        
        
    
    
    
    
        
            
                io.spring.platform
                platform-bom
                Cairo-RELEASE
                pom
                import
            
        
    
    
    
    
        spring-boot-infrastructure-projects
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/235664.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号