前提:
- 本地安装了jdk,并配置系统变量JAVA_HOME,Path
- 本地下载了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即可。