本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

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


阅读全文(1744) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.422 second(s), page refreshed 144755273 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号