@Resource注解的相关了解

/*
* FIXME 从现在的情况来看,在Spring-boot中注解@Resource是至关重要的,如果没有@
* Resource注解的话前台传递过来的数据无法传递到service层中去!!!
*
* System.out.println("**************************");
* System.out.println(pageIndex); System.out.println(pageSize);
* System.out.println("**************************"); 1、前台的数据无法传递到controller层
* 2、controller参数无法传递到service层中去 3、会报java.lang.NullPointerException: null的错误
*
*/

 

 

The Resource annotation marks a resource that is
needed by the application. This annotation may be
applied to an application component class, or to
fields or methods of the component class. When the
annotation is applied to a field or method, the
container will inject an instance of the requested
resource into the application component when the
component is initialized. If the annotation is
applied to the component class, the annotation
declares a resource that the application will look
up at runtime. Even though this annotation is not
marked Inherited, deployment tools are required to
examine all superclasses of any component class to
discover all uses of this annotation in all
superclasses. All such annotation instances specify
resources that are needed by the application
component. Note that this annotation may appear on
private fields and methods of superclasses; the
container is required to perform injection in these
cases as well. Since:Common Annotations 1.0

资源注释标记应用程序所需的资源。此批注可以应用于应用程序组件类,或应用于组件类的字段或方法。当注释应用于字段或方法时,容器将在初始化组件时将所请求资源的实例注入应用程序组件。如果注释应用于组件类,则注释将声明应用程序将在运行时查找的资源。
即使此批注未标记为Inherited,也需要部署工具检查任何组件类的所有超类,以发现此批注在所有超类中的所有用法。所有这些注释实例都指定了应用程序组件所需的资源。请注意,此批注可能出现在超类的私有字段和方法上;在这些情况下,容器也需要进行注射。
@Resource注解开发者注释

 

1、降低耦合度。

2、Spring boot 中必须注解(大概吧)(具体的情况还要深入研究一下)

  @Resource
    private IRatedVolPowerFreqService ratedVolPowerFreqService;

    /**
     * 列表界面
     */
    @RequestMapping(value = "list")
    public String list(RatedVolPowerFreq ratedVolPowerFreq, Integer pageIndex, Integer pageSize,
            ModelMap model) {
        PageModel<RatedVolPowerFreq> page = ratedVolPowerFreqService.findByPage(ratedVolPowerFreq,
                pageIndex, pageSize);
        model.put("ratedVolPowerFreq", ratedVolPowerFreq);
        model.put("page", page);
        return "mes/ratedVolPowerFreq/list";
    }

  

 

我觉的算是半必须的内容,具体情况还要深入研究一下

posted @ 2018-07-18 11:26  血肉苦弱机械飞升  阅读(459)  评论(0编辑  收藏  举报
跟随粒子特效