Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7595745 建立时间:2006年5月29日 |

| |
[Java Open Source]compass 中使用annatation 简化配置 软件技术, 电脑与网络
lhwork 发表于 2006/6/28 21:56:54 |
Compass也提供另一直配置, 使用java5 的annotation 来进行OSEM. 下面就是简单的Plain Old Java Object (POJO)类型的搜索类,使用了Compass annotations.在运行时刻, compass抽取对象属性插入和相应源数据索引中. 500)this.width=500'>500)this.width=500'>public class Product 500)this.width=500'>{ 500)this.width=500'> @SearchableId500)this.width=500'> private Integer id;500)this.width=500'> private Category category;500)this.width=500'> private Integer inventory;500)this.width=500'> private String name;500)this.width=500'> private String descn;500)this.width=500'> private Double unitprice;500)this.width=500'> private String status;500)this.width=500'> private String shortDescn = null;500)this.width=500'> private Date createTime;500)this.width=500'> private Date modifyTime;500)this.width=500'> private User createUser;500)this.width=500'> private User modifyUser;500)this.width=500'> @SearchableProperty(name = "name")500)this.width=500'>500)this.width=500'> public String getName() 500)this.width=500'>{500)this.width=500'> return this.name;500)this.width=500'> }500)this.width=500'> @SearchableProperty(name = "descn")500)this.width=500'>500)this.width=500'> public String getDescn() 500)this.width=500'>{500)this.width=500'> return this.descn;500)this.width=500'> }500)this.width=500'>500)this.width=500'> public Double getUnitprice() 500)this.width=500'>{500)this.width=500'> return this.unitprice;500)this.width=500'> }500)this.width=500'>500)this.width=500'> public void setUnitprice(Double unitprice) 500)this.width=500'>{500)this.width=500'> this.unitprice = unitprice;500)this.width=500'> }500)this.width=500'> setter/getter500)this.width=500'>500)this.width=500'>500)this.width=500'>@Searchable(alias = "book")500)this.width=500'>500)this.width=500'>public class Book extends Product 500)this.width=500'>{500)this.width=500'> private String image;500)this.width=500'> private String author;500)this.width=500'> private String publisher;500)this.width=500'> private String publishDate;500)this.width=500'>500)this.width=500'> public Book() 500)this.width=500'>{}500)this.width=500'>500)this.width=500'> public String getImage() 500)this.width=500'>{500)this.width=500'> return image;500)this.width=500'> }500)this.width=500'>500)this.width=500'> public void setImage(String image) 500)this.width=500'>{500)this.width=500'> this.image = image;500)this.width=500'> }500)this.width=500'> @SearchableProperty(name = "author")500)this.width=500'>500)this.width=500'> public String getAuthor() 500)this.width=500'>{500)this.width=500'> return author;500)this.width=500'> }500)this.width=500'>500)this.width=500'> public void setAuthor(String author) 500)this.width=500'>{500)this.width=500'> this.author = author;500)this.width=500'> }500)this.width=500'> @SearchableProperty(name = "publisher")500)this.width=500'>500)this.width=500'> public String getPublisher() 500)this.width=500'>{500)this.width=500'> return publisher;500)this.width=500'> }500)this.width=500'>500)this.width=500'> public void setPublisher(String publisher) 500)this.width=500'>{500)this.width=500'> this.publisher = publisher;500)this.width=500'> }500)this.width=500'>500)this.width=500'> public String getPublishDate() 500)this.width=500'>{500)this.width=500'> return publishDate;500)this.width=500'> }500)this.width=500'>500)this.width=500'> public void setPublishDate(String publishDate) 500)this.width=500'>{500)this.width=500'> this.publishDate = publishDate;500)this.width=500'> }500)this.width=500'>}注意: 对象必须遵守下面的规则. 1. 所有的持久化类必须有默认构造函数(没参数构造方法).2. OSEM要求映射类JavaBean必须有一个或更多的id主建. id属性可以是对象类型,例如java.lang.String or java.util.Date. 并且类注解使用@SearchableClassConverter或者使用定义Converter(通常继承Compass AbstractBasicConverter).3. 使用JavaBean规范, getter/setter. 更多:@Searchable,@SearchableId,@SearchableProperty and So On Look: http://www.opensymphony.com/compass/content/documentation.html |
|
|