IDEA+Gradle+SpringBoot 創建spring web項目

 

前提:

  1. 本地安裝了jdk,並配置系統變量JAVA_HOME,Path
  2. 本地下載了gradle-4.10u並配hu系統變量GRAhuLEchHOME,Path

1.打開IDEA,創建project項目

2.項目管理工具選擇gradle,點擊Next

3.勾選項目基本組成部分

4.點擊Finish創建項目

5.項目目錄結構如下,標紅部分是自己創的

注意,如果demoo2項目文件夾爲普通文件,無法新建package,需要點擊如下圖標,將src標註爲Source

6.編輯WelcomeController的內容

7.編輯index.html的內容

8.配置build.gradle的內容

文本如下

plugins {
    id 'org.springframework.boot' version '2.1.4.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-web-services'
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.1'
    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'mysql:mysql-connector-java'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    compile group:'org.springframework.boot',name:'spring-boot-devtools',version: '2.0.4.RELEASE'//熱部署
}

9.配置application.properties文件,內容如下

 

文本如下:

spring.datasource.url=jdbc:mysql:/localhost:3306/test?useUnicode=true&CharacterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


spring.thymeleaf.cache=false

10.配置完畢,啓動項目

注意,默認端口是8080,你可以在application.properties文件中添加server.port=8090進行修改端口號,瀏覽器中輸入:

localhost:8090/welcome即可。 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章