springboot

Springboot注解大全

2019-10-10  本文已影响0人  毛不翼

一、注解(annotations)列表

二、注解(annotations)详解

@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class Application {
     public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
     }
}
@RequestMapping(“/test”)
@ResponseBody
public String test(){
    return”ok”;
}
@Controller
@RequestMapping(“/demoInfo”)
publicclass DemoController {
    @Autowired
    private DemoInfoService demoInfoService;

    @RequestMapping("/hello")
    public String hello(Map<String,Object> map){
        System.out.println("DemoController.hello()");
        map.put("hello","from TemplateController.helloHtml");
        //会使用hello.html或者hello.ftl模板进行渲染显示.
        return"/hello";
    }
}
@RestController
@RequestMapping(“/demoInfo2”)
publicclass DemoController2 {

    @RequestMapping("/test")
    public String test(){
        return"ok";
    }
}
@Value(value = “#{message}”)
private String message;
@Autowired
@Qualifier(value = “demoInfoService”)
private DemoInfoService demoInfoService;

三、JPA注解

四、springMVC相关注解

RequestMapping(“user/get/mac/{macAddress}”)
public String getByMacAddress(@PathVariable String macAddress){
    //do something;
}

参数与大括号里的名字一样要相同。

五、全局异常处理

上一篇 下一篇

猜你喜欢

热点阅读