第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Spring Boot 基礎(chǔ)框架 - Spring MVC + Thymleaf 環(huán)境搭建、配置

標(biāo)簽:
SpringBoot

搭建基本环境

目前Spring 官方提供了web的方式进行快速构建,可访问地址:https://start.spring.io/ 地址,那这里为了手把手教大家,就自己动手、丰衣足食了,有兴趣的小伙伴可以自己动动小手指,自己DIY

使用Eclipse 创建maven项目
项目名称:spring-boot-infrastructure-projects

打开eclipse , File > New > Maven Project


webp

New Maven project

选择Next >, 选择Artifact Id : maven-archetype-quickstart

webp

maven-archetype-quickstart


选择Next >, 输入项目信息

webp

2018-9-1 12-46-33.png


选择Finish完成

webp

spring-boot-infrastructure-projects


创建源文件:
src/main/resource
src/test/resource

Eclipse > 文件 > 新建 > 新建 Source Folder


webp

src/mian/resources

至此,一个简单的Maven项目构建完成,截图如下


webp

Maven Project Build Finished

配置Spring Boot + Spring MVC  + Thymleaf Hello World 环境

pom.xml文件

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.lab</groupId>
    <artifactId>spring-boot-infrastructure-projects</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>spring-boot-infrastructure-projects</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
    
        <!-- 
            | Spring Boot
         -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        <!-- 
            | thymeleaf
         -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        </dependency>
        
    </dependencies>
    
    <!-- 
        | Spring IO Platform 依赖管理器,将Spring各个组件之间的版本兼容性交给Spring来统一维护管理,避免存在兼容性问题。
     -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>Cairo-RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    
    <build>
        <finalName>spring-boot-infrastructure-projects</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build></project>

配置文件: 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;/**
 * 
 * Spring MVC WebConfig
 * 
 * @author Martin
 * @since 1.0.0
 */@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;/**
 * 
 * Portal Controller
 * 
 * @author Martin
 * @since 1.0.0
 */@Controllerpublic class PortalController {

    @RequestMapping(value="/",method= RequestMethod.GET)
    public String index() {        return "index";
    }
}

最终项目目录结构如下:


webp

Finished



作者:数据服务
链接:https://www.jianshu.com/p/97e8740488f1


點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消