zoukankan      html  css  js  c++  java
  • Spring常用注解

    控制层参数相关注解
    Spring常用注解

        //相当于@PostMapping(“/requestParamTest”)
        @RequestMapping(value="/requestParamTest", method = RequestMethod.POST)
        public String requestParamTest(@RequestParam(value="username") String userName, @RequestParam(value="usernick") String userNick){
        //若前台入参与此处接收参数完全一致,可不用@RequestParam
            System.out.println("requestParam Test");
            System.out.println("username: " + userName);
            System.out.println("usernick: " + userNick);
            return "hello";
        }
    
    @GetMapping(value = {"/list/{deviceTypeId}","/list"})
    public BaseBody getAll(@PathVariable(value = "deviceTypeId",required = false) Long deviceTypeId) throws Exception {
    
    }
    

    @Autowired默认按类型匹配的方式,在容器查找匹配的Bean,当有且仅有一个匹配的Bean时,Spring将其注入@Autowired标注的变量中。
    @Qualifier注解限定Bean的名称
    @Resource,默认通过name属性去匹配bean,找不到再按type去匹配

    @Controller用于标注控制层组件
    @Service对应的是业务层Bean
    @Component是所有受Spring 管理组件的通用形式,@Component注解可以放在类的头上,@Component不推荐使用
    @Repository对应数据访问层Bean

    @Configuration把一个类作为一个IoC容器,它的某个方法头上如果注册了@Bean,就会作为这个Spring容器中的Bean
    @Scope注解 作用域
    @Lazy(true) 表示延迟初始化

    @PostConstruct用于指定初始化方法(用在方法上)
    @PreDestory用于指定销毁方法(用在方法上)

  • 相关阅读:
    用shell脚本监控进程是否存在 不存在则启动的实例
    vue+element-ui+ajax实现一个表格的实例
    c的指针和php中的引用的区别
    mysql or条件查询优化
    Linq查询操作之投影操作
    Linq查询操作之Where筛选
    Linq专题之查询操作
    linq之join子句
    linq之let子句
    linq之into子句
  • 原文地址:https://www.cnblogs.com/xiaobingzi/p/10751402.html
Copyright © 2011-2022 走看看