springBoot注解
@SpringBootApplication
这个注解是Spring Boot最核心的注解,用在 Spring Boot的主类上,标识这是一个 Spring Boot 应用,用来开启 Spring Boot 的各项能力。实际上这个注解是@Configuration,@EnableAutoConfiguration,@ComponentScan三个注解的组合。由于这些注解一般都是一起使用,所以Spring Boot提供了一个统一的注解@SpringBootApplication
@Autowired:
自动导入依赖的bean
@value
@Controller
处理请求http
@RestController
@RestController = @Controller + @ResponseBody组成
@ResponseBody,是指该类中所有的API接口返回的数据,甭管你对应的方法返回Map或是其他Object,它会以Json字符串的形式返回给客户端
@RequestMapping
是 Spring Web 应用程序中最常被用到的注解之一。这个注解会将 HTTP 请求映射到 MVC 和 REST 控制器的处理方法上。配置url映射
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String say(){
return "hello";
}
value: 指定请求的实际地址;
method: 指定请求的method类型, GET、POST、PUT、DELETE等;
@RequestParam
获取前端url传入的参数
url:http://localhost:8080/hello?id=113
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String say(@RequestParam("id") String ID){
return ID;
}

浙公网安备 33010602011771号