-
创建一个新的项目
注意修改为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就搭建好了。