【CRM(二)】登录客户管理模块
生活随笔
收集整理的這篇文章主要介紹了
【CRM(二)】登录客户管理模块
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
CRM綜合練習:用戶模塊登錄功能
用戶模塊:登錄功能代碼實現
修改登錄頁面
<FORM id=form1 name=form1 action="${ pageContext.request.contextPath }/user_login.action" method=post target="_parent">編寫Action中login方法
- UserAction.java
編寫Service實現類
@Override //業務層用戶登陸的方法 public User login(User user) {user.setUser_password(MD5Utils.md5(user.getUser_password()));//調用DAOreturn userDao.login(user); }編寫DAO實現類
@Override //DAO中根據用戶名和密碼進行查詢的方法: public User login(User user) {List<User> list = (List<User>) this.getHibernateTemplate().find("from User where user_code=? and user_password = ?", user.getUser_code(),user.getUser_password());if(list.size() > 0){return list.get(0);}return null; }配置頁面的跳轉
struts.xml
<package name="crm" extends="struts-default" namespace="/"><action name="user_*" class="userAction" method="{1}"><result name="login">/login.jsp</result><result name="success" type="redirect">/index.jsp</result></action> </package>在頁面中顯示數據
- 在登錄成功的頁面上顯示用戶的信息
top.jsp
- 在失敗的頁面上顯示錯誤信息
login.jsp
CRM綜合練習:客戶管理
客戶管理:準備工作
創建表
CREATE TABLE `cst_customer` (`cust_id` bigint(32) NOT NULL AUTO_INCREMENT COMMENT '客戶編號(主鍵)',`cust_name` varchar(32) NOT NULL COMMENT '客戶名稱(公司名稱)',`cust_source` varchar(32) DEFAULT NULL COMMENT '客戶信息來源',`cust_industry` varchar(32) DEFAULT NULL COMMENT '客戶所屬行業',`cust_level` varchar(32) DEFAULT NULL COMMENT '客戶級別',`cust_phone` varchar(64) DEFAULT NULL COMMENT '固定電話',`cust_mobile` varchar(16) DEFAULT NULL COMMENT '移動電話',PRIMARY KEY (`cust_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;創建實體和映射
- 創建實體
- 創建映射
創建Action
創建Service
創建DAO
配置Action、Service、DAO
跳轉到添加頁面
修改左側菜單頁面
編寫Action中的saveUI的方法
配置Action的跳轉
測試跳轉
引入數據字典
什么是數據字典
數據字典用來規范某些地方具體值和數據
創建數據字典表
CREATE TABLE `base_dict` (`dict_id` varchar(32) NOT NULL COMMENT '數據字典id(主鍵)',`dict_type_code` varchar(10) NOT NULL COMMENT '數據字典類別代碼',`dict_type_name` varchar(64) NOT NULL COMMENT '數據字典類別名稱',`dict_item_name` varchar(64) NOT NULL COMMENT '數據字典項目名稱',`dict_item_code` varchar(10) DEFAULT NULL COMMENT '數據字典項目(可為空)',`dict_sort` int(10) DEFAULT NULL COMMENT '排序字段',`dict_enable` char(1) NOT NULL COMMENT '1:使用 0:停用',`dict_memo` varchar(64) DEFAULT NULL COMMENT '備注',PRIMARY KEY (`dict_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; insert into `base_dict`(`dict_id`,`dict_type_code`,`dict_type_name`,`dict_item_name`,`dict_item_code`,`dict_sort`,`dict_enable`,`dict_memo`) values ('1','001','客戶行業','教育培訓 ',NULL,1,'1',NULL),('10','003','公司性質','民企',NULL,3,'1',NULL),('12','004','年營業額','1-10萬',NULL,1,'1',NULL),('13','004','年營業額','10-20萬',NULL,2,'1',NULL),('14','004','年營業額','20-50萬',NULL,3,'1',NULL),('15','004','年營業額','50-100萬',NULL,4,'1',NULL),('16','004','年營業額','100-500萬',NULL,5,'1',NULL),('17','004','年營業額','500-1000萬',NULL,6,'1',NULL),('18','005','客戶狀態','基礎客戶',NULL,1,'1',NULL),('19','005','客戶狀態','潛在客戶',NULL,2,'1',NULL),('2','001','客戶行業','電子商務',NULL,2,'1',NULL),('20','005','客戶狀態','成功客戶',NULL,3,'1',NULL),('21','005','客戶狀態','無效客戶',NULL,4,'1',NULL),('22','006','客戶級別','普通客戶',NULL,1,'1',NULL),('23','006','客戶級別','VIP客戶',NULL,2,'1',NULL),('24','007','商機狀態','意向客戶',NULL,1,'1',NULL),('25','007','商機狀態','初步溝通',NULL,2,'1',NULL),('26','007','商機狀態','深度溝通',NULL,3,'1',NULL),('27','007','商機狀態','簽訂合同',NULL,4,'1',NULL),('3','001','客戶行業','對外貿易',NULL,3,'1',NULL),('30','008','商機類型','新業務',NULL,1,'1',NULL),('31','008','商機類型','現有業務',NULL,2,'1',NULL),('32','009','商機來源','電話營銷',NULL,1,'1',NULL),('33','009','商機來源','網絡營銷',NULL,2,'1',NULL),('34','009','商機來源','推廣活動',NULL,3,'1',NULL),('4','001','客戶行業','酒店旅游',NULL,4,'1',NULL),('5','001','客戶行業','房地產',NULL,5,'1',NULL),('6','002','客戶信息來源','電話營銷',NULL,1,'1',NULL),('7','002','客戶信息來源','網絡營銷',NULL,2,'1',NULL),('8','003','公司性質','合資',NULL,1,'1',NULL),('9','003','公司性質','國企',NULL,2,'1',NULL);客戶表和字典表的關系分析
創建字典的實體和映射
- 創建實體
- 創建映射
修改字典和客戶的關系映射
- 修改了客戶的實體
- 修改客戶的映射
將映射文件交給Spring
在添加頁面上異步加載字典數據
創建字典的Action、Service、DAO
- 編寫DAO
- 編寫Service
- 編寫Action
將字典類交給Spring
引入jquery的js(在添加頁面上)
編寫異步加載的方法
<script type="text/javascript">$(function(){// 頁面加載函數就會執行:// 頁面加載,異步查詢字典數據:// 加載客戶來源$.post("${pageContext.request.contextPath }/baseDict_findByTypeCode.action",{"dict_type_code":"002"},function(data){// 遍歷json的數據:$(data).each(function(i,n){$("#cust_source").append("<option value='"+n.dict_id+"'>"+n.dict_item_name+"</option>");});},"json");}); </script>編寫Action
- 引jar包
編寫Service
public class BaseDictServiceImpl implements BaseDictService {//注入DAOprivate BaseDictDao baseDictDao;public void setBaseDictDao(BaseDictDao baseDictDao) {this.baseDictDao = baseDictDao;}@Overridepublic List<BaseDict> findByTypeCode(String dict_type_code) {return baseDictDao.findByTypeCode(dict_type_code);} }編寫DAO
public class BaseDictDaoImpl extends HibernateDaoSupport implements BaseDictDao {@Override//根據類型編碼查詢字典數據public List<BaseDict> findByTypeCode(String dict_type_code) {return (List<BaseDict>) this.getHibernateTemplate().find("from BaseDict where dict_type_code = ?", dict_type_code);} }加載其他字典項數據
<script type="text/javascript">$(function(){// 頁面加載函數就會執行:// 頁面加載,異步查詢字典數據:// 加載客戶來源$.post("${pageContext.request.contextPath }/baseDict_findByTypeCode.action",{"dict_type_code":"002"},function(data){// 遍歷json的數據:$(data).each(function(i,n){$("#cust_source").append("<option value='"+n.dict_id+"'>"+n.dict_item_name+"</option>");});},"json");$.post("${pageContext.request.contextPath }/baseDict_findByTypeCode.action",{"dict_type_code":"006"},function(data){// 遍歷json的數據:$(data).each(function(i,n){$("#cust_level").append("<option value='"+n.dict_id+"'>"+n.dict_item_name+"</option>");});},"json");$.post("${pageContext.request.contextPath }/baseDict_findByTypeCode.action",{"dict_type_code":"001"},function(data){// 遍歷json的數據:$(data).each(function(i,n){$("#cust_industry").append("<option value='"+n.dict_id+"'>"+n.dict_item_name+"</option>");});},"json");}); </script>保存數據到數據庫中
修改添加頁面
- 修改表單項名稱
編寫Action
編寫Service
編寫DAO
添加事務
CRM綜合練習:客戶管理分頁查詢客戶
查詢客戶(分頁)
修改menu.jsp
編寫Action中findAll的方法
public String findAll(){//接收參數:分頁參數//最好使用DetachedCriteria對象(條件查詢--帶分頁)DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Customer.class);//調用業務層查詢PageBean<Customer> pageBean = customerService.findByPage(detachedCriteria,currPage,pageSize);ActionContext.getContext().getValueStack().push(pageBean);return "findAll";}編寫Service
//業務層分頁查詢客戶的方法public PageBean<Customer> findByPage(DetachedCriteria detachedCriteria, Integer currPage,Integer pageSize) {PageBean<Customer> pageBean = new PageBean<Customer>();//封裝當前頁面pageBean.setCurrPage(currPage);//封裝每頁顯示的記錄數:pageBean.setPageSize(pageSize);//封裝總記錄數//調用DAOInteger totalCount = customerDao.findCount(detachedCriteria);pageBean.setTotalCount(totalCount);//封裝總頁數Double tc = totalCount.doubleValue();Double num = Math.ceil(tc/pageSize);pageBean.setTotalPage(num.intValue());//封裝每頁顯示的數據的集合Integer begin = (currPage - 1) * pageSize;List<Customer> list = customerDao.findByPage(detachedCriteria,begin,pageSize);pageBean.setList(list);return pageBean;}編寫DAO
//DAO中帶條件統計個數public Integer findCount(DetachedCriteria detachedCriteria) {//select count(*) from xxx where 條件;detachedCriteria.setProjection(Projections.rowCount());List<Long> list = (List<Long>) this.getHibernateTemplate().findByCriteria(detachedCriteria);if(list.size()>0){return list.get(0).intValue();}return null;}@Override//DAO中分頁查詢客戶的方法public List<Customer> findByPage(DetachedCriteria detachedCriteria, Integer begin, Integer pageSize) {detachedCriteria.setProjection(null);return (List<Customer>) this.getHibernateTemplate().findByCriteria(detachedCriteria, begin, pageSize);}配置頁面跳轉
在list.jsp中顯示數據(分頁顯示)
<DIVstyle="LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: right">共[<B><s:property value="totalCount"/></B>]條記錄,[<B><s:property value="totalPage"/></B>]頁,每頁顯示<select name="pageSize" onchange="to_page()"><option value="3" <s:if test="pageSize == 3">selected</s:if>>3</option><option value="5" <s:if test="pageSize == 5">selected</s:if>>5</option><option value="10" <s:if test="pageSize == 10">selected</s:if>>10</option></select>條<s:if test="currPage != 1">[<A href="javascript:to_page(1)">首頁</A>][<A href="javascript:to_page(<s:property value="currPage-1"/>)">前一頁</A>]</s:if> <B><s:iterator var="i" begin="1" end="totalPage"><s:if test="#i == currPage"><s:property value="#i"/></s:if><s:else><a href="javascript:to_page(<s:property value="#i"/>)"><s:property value="#i"/></a></s:else></s:iterator></B><s:if test="currPage != totalPage">[<A href="javascript:to_page(<s:property value="currPage+1"/>)">后一頁</A>] [<A href="javascript:to_page(<s:property value="totalPage"/>)">尾頁</A>] </s:if>到<input type="text" size="3" id="page" name="currPage" />頁<input type="button" value="Go" onclick="to_page()"/> </DIV>總結
以上是生活随笔為你收集整理的【CRM(二)】登录客户管理模块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows系统中的剪切板记录如何开启
- 下一篇: jQuery常用插件网址