IDEA创建一个Spring Boot入门项目

最基础的项目构建方法:
  • 此方式【新建项目】区别于 通过 生成器 “构建项目”。
  • 这只是建一个简单的项目。
    在这里插入图片描述

构建Spring Boot项目

方式1:创建maven工程

创建一个maven工程(建议:java工程,也可以是web工程),无需勾选maven骨架。

超详细的Springboot入门教程,看了必会


方式2:创建spring initializr工程

(1)通过idea工具创建工程时,不再选择maven了而是选择spring initializr。然后去勾选相关依赖。

如果默认服务器URL不行可以换为 https://start.aliyun.com/

在这里插入图片描述在这里插入图片描述
项目IDEA中呈现:
在这里插入图片描述

如果有自己配置的maven仓库的话,就要在setting里面设置,点击file - setting- 直接搜索maven,就可以看到。在这里可以配置自己的maven版本和仓库。

在这里插入图片描述

(2)添加到maven,重新加载项目;
(3)执行HelloworldApplication程序;
在这里插入图片描述
到这里,idea的开发环境已经搭建好。


(4)编写HelloController

  • 在工程的src目录下创建 package com.lzl.helloworld.helloController 文件夹
    注:【helloController】文件夹与 HelloworldApplication 文件在一级目录。
  • 创建 HelloController
    在这里插入图片描述

HelloController文件:

package com.lzl.helloworld.helloController;

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

@RestController
public class HelloController {
    /**
     * 请求 /hello  输出hello springboot!
     * @return
     */
     
    @GetMapping(value = "/hello")
    public String hello(){
        return "hello World!";
    }
    
//    @GetMapping("/hello")
//    public String hello(@RequestParam(value = "name", defaultValue = "Worldddddddd") String name) {
//        return String.format("Hello %s!", name);
//    }
}

HelloworldApplication文件:

package com.lzl.helloworld;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class HelloworldApplication {

	public static void main(String[] args) {
		// 只需要run一下,就能发布一个springboot应用
		// 相当于之前将web工程发布到tomcat服务器,只是在springboot中集成了tomcat插件
		SpringApplication.run(HelloworldApplication.class, args);
	}
}

(5)启动项目。
(6)在浏览器中打开 http://localhost:8080/hello
在这里插入图片描述


官方文档: https://spring.io/quickstart
SpringBoot学习之《深入浅出SpringBoot》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值