SpringBoot入门

如何快速创建一个springboot项目,使用idea自带的

创建好后,启动springboot服务

编写测试类

package com.example.springdemo.demo.test;

import com.example.springdemo.ServerTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@Controller
@RequestMapping(value = "/api")
public class Day01 {

    @Resource
    private ServerTest serverTest;

    @RequestMapping(value = "/{start}/{end}")
    @ResponseBody
    public Map myGetList(@PathVariable Integer start,
                         @PathVariable Integer end){
        serverTest.test();
        Map<String,Integer> myList = new HashMap<>();
        myList.put("鞋12",400);
        myList.put("干脆面321",1);
        myList.put("衬衫",300);
        return  myList;
    }
    @RequestMapping(value = "/index")
    @ResponseBody
    public String index(){
        return  "index_page";

    }
}

注解说明

Springboot项目启动入口

@SpringBootApplication  //启动入口

@ComponentScan(basePackages = {"com.example.springdemo.demo", "com.example.springdemo"}) //扫描包

control层

类上方标记

@Controller
@RequestMapping(value = "/api") //映射的路径

类变量应用

@Resource //引入其他类

类方法

@RequestMapping(value = "/{start}/{end}")

@ResponseBody

类方法入参应用

@PathVariable Integer start

 执行效果如下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值