<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- 配置连接参数 -->
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
value="jdbc:sqlserver://127.0.0.1:1433;databaseName=xe">
</bean>
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 依赖数据源 -->
<!-- hibernate相关配置 -->
org.hibernate.dialect.SQLServerDialect
true
true
com/tarena/entity/Cost.hbm.xml
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
tx:attributes
/tx:attributes
/tx:advice
pointcut="within(com.tarena.action.*)"/>
/aop:config
package com.tarena.entity;
import java.sql.Date;
public class Cost {
private Integer id;
private String name;
private Integer baseDuration;
private Double baseCost;
private Double unitCost;
private String status;
private String descr;
private Date createTime;
private Date startTime;
private String costType;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getBaseDuration() {
return baseDuration;
}
public void setBaseDuration(Integer baseDuration) {
this.baseDuration = baseDuration;
}
public Double getBaseCost() {
return baseCost;
}
public void setBaseCost(Double baseCost) {
this.baseCost = baseCost;
}
public Double getUnitCost() {
return unitCost;
}
public void setUnitCost(Double unitCost) {
this.unitCost = unitCost;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getDescr() {
return descr;
}
public void setDescr(String descr) {
this.descr = descr;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public String getCostType() {
return costType;
}
public void setCostType(String costType) {
this.costType = costType;
}
}
package com.tarena.dao;
import java.util.List;
import com.tarena.entity.Cost;
public interface ICostDao {
List findAll();
}
package com.tarena.dao;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import com.tarena.entity.Cost;
@Repository
public class CostDaoImpl
extends HibernateDaoSupport implements ICostDao {
@Resource
public void setSF(SessionFactory sf){
super.setSessionFactory(sf);
}
public List findAll() {
String hql="from Cost";
return getHibernateTemplate().find(hql);
}
}
package com.tarena.action;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.tarena.dao.ICostDao;
import com.tarena.entity.Cost;
@Controller
@Scope("prototype")
public class FindCostAction {
@Resource
private ICostDao costDao;
private List costs;
public String load(){
costs=costDao.findAll();
return "success";
}
public List getCosts() {
return costs;
}
public void setCosts(List costs) {
this.costs = costs;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
find_cost.jsp
<%@ page pageEncoding="UTF-8" isELIgnored="false"%>
<%@taglib uri="/struts-tags" prefix="s"%>
/s:iterator