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的入口