SSH_06
2018-09-05 本文已影响0人
编程_书恨少
1. 如何进行查询的sql书写
select dd.dict_item_name, count(*) totalCount from t_customer c, data_dict dd
where c.cust_industry = dd.dict_id group by cust_industry;
Snip20180905_5.png
Snip20180905_6.png
Snip20180905_7.png
2. 按行业查询客户数的需求实现
CustomerDao
public interface CustomerDao extends BaseDao<Customer> {
List<Object[]> getIndustryCount();
}
CustomerDaoImpl
public class CustomerDaoImpl extends BaseDaoImpl<Customer> implements CustomerDao {
@Override
@SuppressWarnings("all")
public List<Object[]> getIndustryCount() {
// 原生sql查询
List<Object[]> list = getHibernateTemplate().execute(new HibernateCallback<List>() {
@Override
public List doInHibernate(Session session) throws HibernateException {
String sql = "select dd.dict_item_name, count(*) total_count from t_customer c, data_dict dd \n" +
"where c.cust_industry = dd.dict_id group by cust_industry";
Query query = session.createQuery(sql);
return query.list();
}
});
return list;
}
}
CustomerService
public interface CustomerService {
// 分页方法
PageBean getPageBean(DetachedCriteria dc, Integer currentPage, Integer pageSize);
void save(Customer customer);
List<Object[]> getIndustryCount();
}
CustomerServiceImpl
// 按照行业查询客户数
@Override
public List<Object[]> getIndustryCount() {
return customerDao.getIndustryCount();
}
CustomerAction
public String industryCount() throws Exception {
List<Object[]> list = customerService.getIndustryCount();
ActionContext.getContext().put("list", list);
return "industryCount";
}
3. 将项目转换为使用spring注解来实现
个人比较喜欢用xml来管理,这里就不上代码了