目录
一、打开idea新建Spring Initializr项目
这里镜像源选择https://start.springboot.io比较快。
jdk版本选择1.8。
选择完点击next:
二、设置项目结构
设置包结构和项目类型,这里我选择maven,Java版本8。
选择完点击next:
三、选择需要的依赖
选择需要的依赖;
注意spring boot的版本,这里选择低版本,高版本容易与其他依赖冲突。
next:
选择finish:
等待依赖下载:
四、配置 application.properties文件
文件内容:
# 应用服务 WEB 访问端口
server.port=8080
spring.datasource.driver-class-name= com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/class_03?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username = root
spring.datasource.password = 123456
jdbc驱动问题:
添加依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
五、编辑控制类helloController
内容:
package com.spring.test;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class helloController {
@RequestMapping
public String helloword(){
return "helloword";
}
}
六、启动项目
打开浏览器访问http://localhost:8080
测试成功!