日期:2014-05-16 浏览次数:20746 次
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html:messages id="error" name="errorMessages">
<font color="red">${error}</font>
</html:messages> 其中name为配置文件中写的
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<bean:message key="login.title"/> key中为配置文件写的public <T> List<T> selectAllObject(Class<T> clazz,Page page) {
String hql0 = "select count(*) from " + clazz.getSimpleName();
String hql = "from " + clazz.getSimpleName();
List<T> Objects = new ArrayList<T>();
// query()是分页实现方法
for(Object obj : this.query(hql0, null, hql, null, page)){
Objects.add((T) obj);
}
return Objects;
}import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Expression;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
protected <T> List<T> selectByExampleEntity(final T exampleEntity,final String propertyName,
final Object startData,final Object endData,final Page page) {
Object object = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Example example = Example.create(exampleEntity); //通过实例创建Example
//通过session获得标准
Criteria criteria = session.createCriteria(exampleEntity.getClass());
//如果以下这3个参数都不为空的时候执行
//propertyName是两个时间对应的列的名字,两个时间是同一列的不同结果
if(propertyName != null && startDate != null && endDate != null){
Criterion c = Expression.between(propertyName, startDate, endDate);
criteria.add((Criterion) c);
}
criteria.add(exa