• Tapestry5的注解之@Inject


    @Inject

    Tapestry5中有好多个有用的注解,今天记录些@Inject相关的东西。

    Injection is Tapestry's way of making a dependency – such as a resource, asset, component, block or service – available in a page, component, mixin or service class.

    Injection是Tapestry中定义从属关系的方式 - 例如,resource, asset, component, block or service - 在page,component,mixin或者服务类中都可以定义。

    胡乱翻译的。

    1 Block Injection 插入一个块儿。。。

    @Inject
    private Block foo; //默认id为foo的
    
    或者
    @Inject @Id(
    "bar") private Block barBlock; //id已经被指定

    2 Resource Injection 资源插入

    • java.util.Locale – The locale for the component (all components within a page use the same locale).
    • org.slf4j.Logger – A Logger instance configured for the component, based on the component's class name. SLF4J is a wrapper around Log4J or other logging toolkits.
    • org.apache.tapestry5.ComponentResources – The resources for the component, often used to generate links related to the component.
    • org.apache.tapestry5.ioc.Messages – The component message catalog for the component, from which localized messages can be generated.
    @Inject
    private ComponentResources resources;

    3 Asset Injection class或者src什么的

    @Inject
    @Path("context:images/top_banner.png")
    private Asset banner;

    4 Service Injection

    这个比较普遍。。。

    5 Request Injection

    这个目前只见过,request.isXHR() ? someZone.getBody() : null;这一种情况。。。

  • 相关阅读:
    enum
    高可用复用类
    int 和 Integer 的区别
    MysqlMd5加密
    软件测试例子
    Wordcount
    大气登录页面
    生成二维码的JAVA
    多态的理解
    打印低头思故乡 java
  • 原文地址:https://www.cnblogs.com/voctrals/p/2972255.html
Copyright © 2020-2023  润新知