1. hibernate
hebernate3.0後可以使用注解自動映射删除配置檔案,加入的包是hibernate-annotations-3.3.1.GA.jar和ejb3-persistence-1.0.1.GA.jar就可以實作(版本可以不同)。
例子:
@Entity
@Table(name="airline")
publicclass AirLine implements Serializable{
private String alid;
private Office ofid;
private String name;
private String netaddress;
private String code;
private String moneyphone;
private String ticketphone;
private Integer impower;
private Integer type ;
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid",strategy="uuid.hex")
public String getAlid() {
returnalid;
}
publicvoid setAlid(String alid) {
this.alid = alid;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ofid")
public Office getOfid() {
returnofid;
}
publicvoid setOfid(Office ofid) {
this.ofid = ofid;
}
public String getName() {
returnname;
}
publicvoid setName(String name) {
this.name = name;
}
public String getNetaddress() {
returnnetaddress;
}
publicvoid setNetaddress(String netaddress) {
this.netaddress = netaddress;
}
public String getCode() {
returncode;
}
publicvoid setCode(String code) {
this.code = code;
}
public String getMoneyphone() {
returnmoneyphone;
}
publicvoid setMoneyphone(String moneyphone) {
this.moneyphone = moneyphone;
}
public String getTicketphone() {
returnticketphone;
}
publicvoid setTicketphone(String ticketphone) {
this.ticketphone = ticketphone;
}
public Integer getImpower() {
returnimpower;
}
publicvoid setImpower(Integer impower) {
this.impower = impower;
}
public Integer getType() {
returntype;
}
publicvoid setType(Integer type) {
this.type = type;
}
}
隻有主鍵和關聯外鍵有注釋其他都可以沒有注釋。
2. struts2
struts2.1後可以使用“約定大約”插件實作0配置檔案,規則是傳回值為jsp的一部分名稱jsp的全名為“類名”-“傳回值”中間橫杠隔開---convention_plugin.jar。
例子:
publicclass HelloWordAction{
publicString list(){
return“list”;
}
}
對應的jsp頁面是:hello-word-list.jsp類名要小寫多個單詞的用橫崗隔開傳回值在最後。
3. spring
spring2.1以後set()、get()方法注入可以自動注入不用寫set()、get()方法。
例子:
@Autowired
private FeatureManager featureManager;
不用再寫出featureManager的set()、get()方法了,在applicationContext.xml中這樣配置:
<!-- 使用annotation 自動注冊bean,并保證@Required,@Autowired的屬性被注入 -->
<context:component-scan base-package="org.eline.dao,org.eline.service" />
放在最外層的<beans>下
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
……之前不變在最後加入
<!-- 自動注入實體bean -->
<property name="packagesToScan" value="org.eline.entity*.*" />
</bean>
就可以使用了
4,struts2配置action的入口