一.创建项目

第一步:打开vscode按下shift+ctrl+p,选择下面的

第二步:选择版本

第三步:选择语言

第四步:填写项目的Groupid

第五步:填写Artifact id

第六步:选择打包方式

第七步:选择java版本

第八步:选择依赖工具

二.创建项目目录如下:

二.建立HelloController.java内容如下:

package example.example1;


import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin // 允许所有跨域请求(仅用于开发)
public class HelloController {
    
    @GetMapping("/hello")
    public String hello() {
        return "你好,Spring Boot! 当前时间: " + new java.util.Date();
    }
}

三.点击主程序(Example1Application.java)点击运行

四.打开浏览器,输入:http://localhost:8080/hello

这样一个简单的spring boot项目就成功部署啦!

问题

有时候,我们在使用maven+spring boot来搭建项目时,经常遇到一个问题,就是在pom.xml文件中导入数据库(mysql)驱动版本老是不稳定,报错,这里给大家提供一个通用的思路,就是删除版本,像这样

<!-- 正确写法1:不指定版本 -->
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
</dependency>

删除你指定的版本号,让 Spring Boot 自动选择兼容版本:

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐