在IDEA中创建第一个Spring Boot应用

1.创建springboot项目

Next后边的步骤都是平时用的,这里就不再放图出来了

2.编写一个简单代码进行测试

在SpringbootApplication.java中:

package cn.ysjh.springboot2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@SpringBootApplication
@Controller
@Configuration
public class SpringbootApplication {

    @RequestMapping("hello")
    @ResponseBody
    public String hello(){
        return "hello ys!";
    }

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

注解说明:

@SpringBootApplication:Spring Boot项目的核心注解,主要目的是开启自动配置

@Configuration:这是一个配置Spring的配置类

@Controller:标明这是一个SpringMVC的Controller控制器

3.运行

直接运行SpringbootApplication.java中的main方法

4.在浏览器中查看

输入   localhost:8080/hello   就可以看到效果

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值