如何快速创建一个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
执行效果如下