Hello.java分析

Double-click the Hello.java file to view it.

The Hello class, called a managed bean class, provides getter and setter methods for the name property used in the Facelets page expressions. By default, the expression language refers to the class name, with the first letter in lowercase (hello.name).

package javaeetutorial.hello1;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class Hello {

    private String name;

    public Hello() {
    }

    public String getName() {
        return name;
    }

    public void setName(String user_name) {
        this.name = user_name;
    }
}

If you use the default name for the bean class, you can specify @Model as the annotation instead of having to specify both @Named and @RequestScoped. The @Model annotation is called a stereotype, a term for an annotation that encapsulates other annotations. It is described later in Using Stereotypes in CDI Applications. Some examples will use @Model where it is appropriate.

译文:

双击该Hello.java文件以查看它。

Hello类,称为管理bean类,提供了getter和setter方法name中的Facelets页面表达式中使用属性。默认情况下,表达式语言引用类名,第一个字母为小写(hello.name)。

package javaeetutorial.hello1;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class Hello {

    private String name;

    public Hello() {
    }

    public String getName() {
        return name;
    }

    public void setName(String user_name) {
        this.name = user_name;
    }
}

如果使用bean类的默认名称,则可以指定@Model 为注释,而不必指定两者@Named和 @RequestScoped。该@Model注释称为刻板印象,是用于封装其他注释的注释术语。稍后将在CDI应用程序使用定型。一些示例将使用@Model适当的地方。

原文地址:https://www.cnblogs.com/hcwys/p/8692428.html