- 创建一个新的项目
编辑
注意修改为maven项目以及修改java对应版本号。
编辑
注意修改springboot版本号,同时添加mysqlDriver,SpringDataJpa,前端框架根据自身需求(这边用到的是thymeleaf)
编辑
2. 修改application文件
编辑
对应接口号,对应数据库名hexin(根据自身变化设置),数据库用户以及密码
server.port=8080
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/hexin
spring.datasource.username=root
spring.datasource.password=123456
3. 新建Hello文件
编辑
package com.example.test1;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
//restcontroller与controller的区别在于,rest返回实体,controller返回模块html
@RequestMapping("/hello")
public class Hello {
@RequestMapping("/hexin")
public String hello(){
return "helloSpring!!!";
}
}
4. 运行项目。
编辑
一个简单的springboot就搭建好了。