简体   繁体   English

Java Bean中的自定义类变量

[英]Custom class variables in a Java Bean

I was reading about Java beans, and all the examples I came across use standard Java types (String, int, etc) for class variables. 我正在阅读有关Java bean的文章,遇到的所有示例都将标准Java类型(字符串,整数等)用于类变量。 Can I use variables of my own class type in a bean? 我可以在bean中使用我自己的类类型的变量吗?

Eg. 例如。

class MyBean implements java.io.Serializable{
    MyObj mo;
    public MyBean(){}
    //Getter and setter for mo
}

(Writing this from a phone, so apologize for no formatting) (用手机写的,为此不致歉意)

Yes, you can. 是的你可以。

You can implement your own business logic using POJO defined by yourself plugging reusable components as well. 您还可以使用自己插入可重用组件定义的POJO来实现自己的业务逻辑。

If you use JSF remember to create setter and getter for your variables if you want to access them from your JSP/Facelets pages. 如果您使用JSF,请记住为您的变量创建setter和getter,如果您想从JSP / Facelets页面访问它们。 The naming convention is pretty standard, if you have a String named 'foo' the framework will call the 命名约定非常标准,如果您有一个名为“ foo”的字符串,则框架将调用

public String getFoo() 
{ 
  return foo;
}  

method. 方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM