SSH_06
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;
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來管理,這裡就不上程式碼了