ps:昨天将管理员登录的功能完成了,并完美的解决跳过登录从而进入管理界面的bug,今天我们将实现"查询用户"功能。

①在po包中创建Customer类,并编写相关变量和添加set/get方法。(相关变量:客户编号,客户名称,负责人id,创建人id,客户信息来源,客户所属行业,客户级别,联系人,固定电话,移动电话,邮政编码,联系地址,创建时间,起始行,所取行数) 然后创建BaseDict类(字典类)

②在dao包中创建CustomerDao接口,接口中包含 通过id查询客户的方法,客户列表方法(List集合)和显示客户数的方法

③在dao包中创建CustomerDao.xml文件,在文件开头我们先编写映射地址,然后编写查询用户的sql语句,其id为
"selectCustomerListWhere" 
然后编写查询客户列表的sql语句(查询客户列表的语句要和字典表结合来查)。之后编写查询客户总数的sql语句。

<mapper namespace="com.yehaijing.core.dao.CustomerDao" >
<!-- 查询客户 -->
<sql id="selectCustomerListWhere">
<where>
<if test="cust_name != null" >
cust_name like "%"#{cust_name}"%"
</if>
<if test="cust_source != null" >
and cust_source = #{cust_source}
</if>
<if test="cust_industry != null" >
and cust_industry = #{cust_industry}
</if>
<if test="cust_level != null" >
and cust_level = #{cust_level}
</if>
</where>
</sql>
<!-- 查询客户列表 -->
<select id="selectCustomerList" parameterType="customer"
resultType="customer">
SELECT
cust_id,
cust_name,
cust_user_id,
cust_create_id,
b.dict_item_name cust_source,
c.dict_item_name cust_industry,
d.dict_item_name cust_level,
cust_linkman,
cust_phone,
cust_mobile,
cust_createtime
FROM
customer a
LEFT JOIN (
SELECT
dict_id,
dict_item_name
FROM
base_dict
WHERE
dict_type_code = '002'
) b ON a.cust_source = b.dict_id
LEFT JOIN (
SELECT
dict_id,
dict_item_name
FROM
base_dict
WHERE
dict_type_code = '001'
) c ON a.cust_industry = c.dict_id
LEFT JOIN (
SELECT
dict_id,
dict_item_name
FROM
base_dict
WHERE
dict_type_code = '006'
@Controller
public class CustomerController {
// 依赖注入
@Autowired
private CustomerService customerService;
@Autowired
private BaseDictService baseDictService;
// 客户来源
@Value("${customer.from.type}")
private String FROM_TYPE;
// 客户所属行业
@Value("${customer.industry.type}")
private String INDUSTRY_TYPE;
// 客户级别
@Value("${customer.level.type}")
private String LEVEL_TYPE;
/**
* 客户列表
*/
@RequestMapping(value = "/customer/list.action")
public String list(@RequestParam(defaultValue="1")Integer page,
@RequestParam(defaultValue="10")Integer rows,
String custName, String custSource, String custIndustry,
String custLevel, Model model) {
// 条件查询所有客户
Page<Customer> customers = customerService
.findCustomerList(page, rows, custName,
custSource, custIndustry,custLevel);
model.addAttribute("page", customers);
// 客户来源
List<BaseDict> fromType = baseDictService
.findBaseDictByTypeCode(FROM_TYPE);
// 客户所属行业
List<BaseDict> industryType = baseDictService
.findBaseDictByTypeCode(INDUSTRY_TYPE);
// 客户级别
List<BaseDict> levelType = baseDictService
.findBaseDictByTypeCode(LEVEL_TYPE);
// 添加参数
model.addAttribute("fromType", fromType);
model.addAttribute("industryType", industryType);
model.addAttribute("levelType", levelType);
model.addAttribute("custName", custName);
model.addAttribute("custSource", custSource);
model.addAttribute("custIndustry", custIndustry);
model.addAttribute("custLevel", custLevel);
return "customer";
}
}

) d ON a.cust_level = d.dict_id<include
refid="selectCustomerListWhere"/><!-- 执行分页查询 --><if
test="start !=null and rows != null">limit
#{start},#{rows}</if></select><!-- 查询客户总数
--><select id="selectCustomerListCount" parameterType="customer"

resultType="Integer">select count(*) from customer<include
refid="selectCustomerListWhere"/></select>

④在service包中创建CustomerService.java接口和BaseDictService.java接口,并在CustomerService接口中编写通过id查询客户的方法,传入customer对象和查询客户列表的方法。在BaseDict接口中编写根据类别代码查询数据字典的方法
findBaseDictByTypeCode。

⑤在service.impl包中创建CustomerServiceImpl.java接口实现类和BaseDictServiceImpl.java接口实现类,并在方法名上添加@Service注解和在方法内部添加@Autowired自动注入

⑥在Controller包中创建CustomerController.java类,在方法名上方加上@Controller注解,在方法内@Autowired自动注入CustomerService和BaseDictService。

@Controller
public class CustomerController {
// 依赖注入
@Autowired
private CustomerService customerService;
@Autowired
private BaseDictService baseDictService;
// 客户来源
@Value("${customer.from.type}")
private String FROM_TYPE;
// 客户所属行业
@Value("${customer.industry.type}")
private String INDUSTRY_TYPE;
// 客户级别
@Value("${customer.level.type}")
private String LEVEL_TYPE;
/**
* 客户列表
*/
@RequestMapping(value = "/customer/list.action")
public String list(@RequestParam(defaultValue="1")Integer page,
@RequestParam(defaultValue="10")Integer rows,
String custName, String custSource, String custIndustry,
String custLevel, Model model) {
// 条件查询所有客户
Page<Customer> customers = customerService
.findCustomerList(page, rows, custName,
custSource, custIndustry,custLevel);
model.addAttribute("page", customers);
// 客户来源
List<BaseDict> fromType = baseDictService
.findBaseDictByTypeCode(FROM_TYPE);
// 客户所属行业
List<BaseDict> industryType = baseDictService
.findBaseDictByTypeCode(INDUSTRY_TYPE);
// 客户级别
List<BaseDict> levelType = baseDictService
.findBaseDictByTypeCode(LEVEL_TYPE);
// 添加参数
model.addAttribute("fromType", fromType);
model.addAttribute("industryType", industryType);
model.addAttribute("levelType", levelType);
model.addAttribute("custName", custName);
model.addAttribute("custSource", custSource);
model.addAttribute("custIndustry", custIndustry);
model.addAttribute("custLevel", custLevel);
return "customer";
}
}

总结:

写到这里,我们的查询客户的功能就全部写完了,回顾一下我们做了什么工作:首先,我们先创建了POJO类(用户类和字典表类),然后我们在dao包中创建了用户类和字典表类的对应接口,并且还对应的创建了xml文件。然后是service类,在service中我们仍然还是创建了接口,并且之后创建了该接口的实现类,最后在controller包中创建了控制类(我觉得这个类相当于一个开关 OFF/ON)。那么将这个项目发布到Tomocat服务器上,浏览器的执行顺序是这样子的:我们在网页上点击操作,然后浏览器首先会查看教程(一)中写好的配置文件(applicationContext.xml等~),然后会首先进入到Controller类中,检查RequestMapping的映射路径(看图)

Boot-crm管理系统开发教程(二)的更多相关文章

  1. Boot-crm管理系统开发教程(总结)

    这个Boot-crm管理系统我花了大概两周写完,因为是刚学完SSM框架,所以立马开始了这个项目,项目初期,运行书本上给的前端代码都报了许多错误,导致这个原因是因为书本给的 设计说明文档 没有看清楚.然 ...

  2. MIP开发教程(二) 使用MIP-CLI工具调试MIP网页

    初始化 MIP 配置 新建一个 MIP 网页 编写 MIP 网页代码 校验 MIP 网页 调试 MIP 网页 1. 初始化 MIP 配置 首先在html目录下进行初始化 MIP 配置: $ mip i ...

  3. 公众号第三方平台开发 教程二 component_verify_ticket和accessToken的获取

    公众号第三方平台开发 教程一 创建公众号第三方平台 公众号第三方平台开发 教程二 component_verify_ticket和accessToken的获取 公众号第三方平台开发 教程三 微信公众号 ...

  4. XAF应用开发教程(二)业务对象模型之简单类型属性

    使用过ORM的朋友对这一部分理解起来会非常快,如果没有请自行补习吧:D. 不说废话,首先,我们来开发一个简单的CRM系统,CRM系统第一个信息当然是客户信息.我们只做个简单 的客户信息来了解一下XAF ...

  5. Boot-crm管理系统开发教程(三)

    (ps:前两章我们已经把管理员登录和查看用户的功能实现了,那么今天我们将要实现:添加用户,删除用户,和修改用户功能) 由于Cusomer的POJO类型已经写好了,所以这次我们之前从CustomerCo ...

  6. Odoo 二次开发教程(二)-模块的基础构建

    注:本篇及后续均以8.0为基础. 一. Odoo模块的构成 __init__.py 文件是python包导入所必须的文件,内容可以为空,通常情况下我们用来导入自己写的py文件. __openerp__ ...

  7. 【转载】Vue 2.x 实战之后台管理系统开发(二)

    2. 常见需求 01. 父子组件通信 a. 父 -> 子(父组件传递数据给子组件) 使用 props,具体查看文档 - 使用 Prop 传递数据(cn.vuejs.org/v2/guide/co ...

  8. Boot-crm管理系统开发教程(一)

    ps:上周就把这个项目写完了,一直忘记记录,现在补上. Boot-crm是书上第十八章的内容,书上提供了前端的代码,所以只需要写后端的代码就可以了,①所以我们先把前端的代码移植到项目中. ②然后在li ...

  9. Android OpenGL ES 开发教程 从入门到精通

    感谢,摘自:http://blog.csdn.net/mapdigit/article/details/7526556 Android OpenGL ES 简明开发教程 Android OpenGL ...

随机推荐

  1. HDFS 特殊权限位

    HDFS 特殊权限位 标签(空格分隔): Hadoop 之前对HDFS更或者说是对Linux中文件的权限没有进行一个完整的学习,只是知道有所有者.所属组和其它权限,具体到某个人的权限有读(r).写(w ...

  2. zookeeper系列(九)zookeeper的会话详解

    作者:leesf    掌控之中,才会成功:掌控之外,注定失败. 出处:http://www.cnblogs.com/leesf456/p/6103870.html尊重原创,大家共同学习: 一.前言 ...

  3. 移动端——meta标签

    meta标签主要辅助HTML结构层的.meta标签不管在互联网前端还是在移动端都起了很重要的作用. <meta http-equiv="Content-type" conte ...

  4. CSS3 新特性

    ~平时喜欢逛博客,看别人的学习总结和遇到的问题解决办法,恰好最近在做书签整理,翻到了之前一个前辈移动前端的总结,所以我就按他的总结模块对自己的知识进行了梳理,不过由于都是手写的,为了方便,下面的都是平 ...

  5. 关于jenkins

    启动不了时可更改端口 java -jar jenkins.war –httpPort=8090

  6. css3_1

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. C++ STL——输入输出流

    [TOC] 注:原创不易,转载请务必注明原作者和出处,感谢支持! 注:内容来自某培训课程,不一定完全正确! 一 缓冲区 (1)标准输入:从键盘输入数据到程序(input) (2)标准输出:程序数据输出 ...

  8. C++代码匈牙利命名规范

    一.类 除了异常类等个别情况(不希望用户把该类看作一个普通的.正常的类之情况)外,C++类/结构的命名应该遵循以下准则: C++类的命名    类的名称都要以大写字母“C”开头,后跟一个或多个单词.为 ...

  9. 012-数据结构-树形结构-哈希树[hashtree]、字典树[trietree]、后缀树

    一.哈希树概述 1.1..其他树背景 二叉排序树,平衡二叉树,红黑树等二叉排序树.在大数据量时树高很深,我们不断向下找寻值时会比较很多次.二叉排序树自身是有顺序结构的,每个结点除最小结点和最大结点外都 ...

  10. jQuery.extend函数

    http://www.cnblogs.com/luckboy/archive/2009/06/25/1510870.html 1.扩展jQuery静态方法. 1$.extend({ 2test:fun ...