.java术语和随机词说明 [英] .java terms and random words clarification

查看:59
本文介绍了.java术语和随机词说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对java,jsf,jsp真的很陌生,我需要学习它是如何快速工作的.因此,我用来练习的网站上有一些术语,例如我不知道它们的含义,我希望有人能解释它们的含义以及它们的用途/目的:)

Im really new to java, jsf, jsp, and I need to learn how it works quickly. So the website Im using to practise has some terms etc that I dont know what they mean and Im hoping somebody can explain what they mean and how/what they are used for:)

Requestscoped
Applicationscoped
Sessionscoped
EntityManager

有人可以引导我完成这些工作吗?

and could someone walk me through what these lines do?

@RequestScoped
public class Dao {

    @DataRepository
    @Inject
    private EntityManager entityManager;

推荐答案

首先,在Java(5及更高版本)中,以" @ "开头的事物"(例如, @Deprecated)称为注释.

First of all, in Java (5 and higher), "things" starting with a @ (e.g. @Deprecated) are called annotations.

注释提供有关不属于该程序的程序程序本身.他们没有直接对代码的操作产生影响他们注释.

Annotations provide data about a program that is not part of the program itself. They have no direct effect on the operation of the code they annotate.

如果要在JSF中使用JavaBean,则需要将其配置为作用域(可以在此处).

Your JavaBeans needs to be configured to a scope if you want to use it in JSF (Definitions can be found here).

  • @RequestScoped :具有此范围的对象从请求开始到结束都是可见的的请求.请求范围始于请求的开始,结束于请求的结束响应已发送到客户端.如果转发了请求,则对象可见在转发的页面中,因为该页面仍是相同请求/响应的一部分循环.具有请求范围的对象可以使用没有对象,请求,会话,或应用范围.如果您必须从Servlet的角度考虑,则托管bean会存储在 HttpServletRequest 中,直到请求结束(将响应发送到客户端时).之后,该bean将不再存在于请求中.
  • @SessionScoped :在任何请求/响应周期中,具有会话范围的对象都是可见的属于一个会话.具有此范围的对象的状态在两个之间保持不变请求并持续到对象或会话无效为止.会话对象作用域可以使用没有作用域,会话作用域或应用程序作用域的其他对象.基本上,这些对象存储在 HttpSession 中(再次参考Servlet).每个会话都有一个与该bean关联的会话ID(称为 JSESSIONID ).
  • ApplicationScoped :具有应用程序范围的对象在所有请求/响应周期中都是可见的对于使用该应用程序的所有客户端,只要该应用程序处于活动状态即可.就Servlet而言,可以是存储在 ServletConfig 中的托管bean.
  • @NoneScoped :具有此范围的对象在任何JSF页面中都不可见.在配置文件中使用时,它们表示由应用程序中的其他托管Bean使用的托管Bean.没有作用域的对象可以使用没有作用域的其他对象.
  • @RequestScoped: Objects with this scope are visible from the start of the request until the end of the request. Request scope starts at the beginning of a request and ends when the response has been sent to the client. If the request is forwarded, the objects are visible in the forwarded page, because that page is still part of the same request/response cycle. Objects with request scope can use other objects with none, request, session, or application scope. If you have to think it in terms of servlet, the managed bean is stored in the HttpServletRequest until the end of the request (when the response is sent to the client). After that, the bean no longer exists in the request.
  • @SessionScoped: An object with session scope is visible for any request/response cycle that belongs to a session. Objects with this scope have their state persisted between requests and last until the object or the session is invalidated. Objects with session scope can use other objects with none, session, or application scope. Basically, these objects are stored in a HttpSession (refer to Servlets again). Each session has a session ID (known as JSESSIONID) that the bean is associated with.
  • ApplicationScoped: An object with application scope is visible in all request/response cycles for all clients using the application, for as long as the application is active. In terms of Servlet, this could be, managed bean stored in a ServletConfig.
  • @NoneScoped: Objects with this scope are not visible in any JSF page. When used in the configuration file, they indicate managed beans that are used by other managed beans in the application. Objects with none scope can use other objects with none scope.

对于 EntityManager ,这与持久性上下文相关联.它用于创建和删除持久实体实例,通过其主键标识查找实体,以及查询所有实体.有关更多信息,请参阅JPA(Java持久性API)规范,或 Hibernate.

@Inject ,表示实例是可注入的.他们遵循臭名昭著的权限注入"或控制反转"(IOC)的字眼.这基本上意味着什么,当资源(在您的情况下为 EntityManagerEntityManager 时)中,JEE容器会为您实例化资源(无需通过例如构造函数等直接实例化资源).

@Inject, means that the instance is injectable. They follow the infamous crase word of Depency Injection or Inversion of Control (IOC). What this basically mean, is that when the resource (in your case EntityManager entityManager is needed, the JEE container instantiates the resource for you (without you needed to instantiate it directly through e.g. a constructor, etc.).

我不知道 @DataRepository 是什么意思.以前从未见过.

I have no clue what @DataRepository means. Never seen it before.

希望对您有帮助.

这篇关于.java术语和随机词说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆