SSH_06

weixin_34075551發表於2018-09-05

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;
2632731-c54cef3abc0933e2.png
Snip20180905_5.png
2632731-9575187f286e05e5.png
Snip20180905_6.png
2632731-d860761433e619ca.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來管理,這裡就不上程式碼了

4.easyUI過時了,直接寫html和js就好了