小言_互联网的博客

IDEA搭建springBoot方式二

369人阅读  评论(0)

1.新建项目




2.写controller

package xiaoliu.springboot04.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {
   

    @RequestMapping("hello")
    @ResponseBody
    public String hello(){
   
        return "这是搭建springBoot第二种方式";
    }
}

3.运行

4.浏览器输入localhost:8080/hello访问项目

两种搭建springBoot方式对比

第一种方式
需要我们自己加入pom依赖

自己写启动spring项目的类

第二种方式
不需要我们自己添加pom依赖,而且启动spring的类也会自动生成,我们只需要定义controller即可

第二种方式相比第一种搭建springBoot方式更加简单快捷


转载:https://blog.csdn.net/qq_41150890/article/details/108986689
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场