(一)IDEA创建首个Springboot案例,访问HelloWorld

创建之前确保我们的idea的maven是配置好的,maven的配置请看我的这篇博客IDEA配置Maven,Maven的下载安装(设置本地仓库与阿里镜像)、配置环境变量
我们将创建springboot并实现连接访问helloworld

创建springboot项目

File->New->Project
在这里插入图片描述
选择Spring Initializr
在这里插入图片描述
这里设置好我们的jdk版本以及项目名称
在这里插入图片描述
选择springboot版本我们这里选择2.3.5,然后勾选spring web
在这里插入图片描述
确认项目路径,然后finish
在这里插入图片描述
删除掉多余的目录与文件
在这里插入图片描述
然后查看maven配置是否正确,idea2020.2版本会自动修改默认值
在这里插入图片描述
在这里插入图片描述
没问题后刷新maven,第一次加载springboot这里可能会报错

	<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                
    </plugin>

需要加入springboot版本就好了,之后创建不用加

	<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.5.RELEASE</version>
    </plugin>
 

测试springboot是否能运行

进入SpringbootHelloApplication类下,这个类便是启动类,@SpringBootApplication注解所在的包以及其子包下的所有的注解都会被扫到,main方法便是springboot的入口。运行main方法

@SpringBootApplication
public class SpringbootHelloApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootHelloApplication.class, args);
    }

}

在这里插入图片描述
这时我们的springboot就已经启动成功了。

访问Helloworld

创建controller目录并创建HelloController类

@RestController
public class HelloController {

    @RequestMapping("Hello")
    public String helloworld(){
        return "hello world";
    }

}

点进@RestController会发现

@Controller
@ResponseBody

这两个注解,所以这里@RestController注解可以理解成@Controller
@ResponseBody这两个注解加起来。
打开浏览器,输入http://127.0.0.1:8080/Hello
在这里插入图片描述
成功!!
可以直接访问是因为我们添加了spring-boot-starter-web依赖
在springboot中嵌入了tomcat服务。

帮助到您请点赞关注收藏谢谢!!!

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值