SpringBoot:使用IDEA快速构建项目

SpringBoot:使用IDEA快速构建项目

之前,我们在官网上直接快速构建了一个springboot项目,IDEA也可以做到,我们来看下具体步骤:

1.创建一个新项目

2.选择spring initalizr , 可以看到默认就是去官网的快速构建工具那里实现

3.和之前一样填写项目信息

 

4.选择初始化的组件

 

5.填写项目路径

 

6.等待项目构建成功

 

测试HelloSpring

1.我们在SpringBootApplication的同路径下,建一个包 controller ,建立一个类HelloSpringBoot

2.编写代码

@RestController
public class HelloSpringBoot {

    @RequestMapping("/hello")
    public String index(){
        return "Hello,SpringBoot!";
    }
}

@RestController 的意思就是 Controller 里面的方法都以 json 格式输出,不用再写什么 jackjson 配置的了!

3.启动主程序,打开浏览器访问 http://localhost:8080/hello,就可以看到效果了!

我们在之后的学习中,直接使用IDEA创建项目即可,方便快捷!这么简单的东西背后一定有故事,我们之后去进行一波源码分析!

猜你喜欢

转载自www.cnblogs.com/hellokuangshen/p/11255967.html