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. hashcode(),equal()方法经典分析

    首先,想要明白hashCode的作用,必须要先知道Java中的集合. 总的来说,Java中的集合(Collection)有两类,一类是List,再有一类是Set. 前者集合内的元素是有序的,元素可以重 ...

  2. maven坐标及依赖范围的学习(1)

    首先,我们先了解什么是maven的坐标(重中之重): 在这里我们可以看到那三个红色的行,基本是pom.xml中出现的最多的配置     例如这个配置:这里我们可以看到我们这个项目的pom文件中,他对名 ...

  3. Java获取当前时间及String、datetime、date相互转化

    一.获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowStrin ...

  4. python 操作excel openpyxl

    1 安装 pip install openpyxl 如果装不上,请指定安装源来安装 pip install -i https://pypi.douban.com/simple openpyxl 如果e ...

  5. 数据结构之双端队列(Deque)

    1,双端队列定义 双端队列:其两端都可以入列和出列的数据结构,如下图所示,队列后面(rear)可以加入和移出数据,队列前面(front)可以加入和移出数据 双端队列操作: deque=Deque() ...

  6. leetcode-hard-ListNode-148. Sort List

    mycode    97.37% 如果用上一个题目中”参考“的方法,res中放节点而不是val,就会超时 # Definition for singly-linked list. # class Li ...

  7. Des加密类

    需要导入Base64.jar包 import java.io.IOException; import java.security.SecureRandom; import javax.crypto.C ...

  8. js-xlsx

    XLSX.read(data, {type: type}); type主要取值如下: base64: 以base64方式读取: binary: BinaryString格式(byte n is dat ...

  9. 京东商城跨域设置Cookie实现SSO单点登陆过程

    可以先看下这边文章:http://blog.chinaunix.net/uid-25508399-id-3431705.html   1.点击首页的登陆按钮跳转到京东的登陆中心https://pass ...

  10. intellij idea如何将web项目打成war包

    1.点击[File]->[Project Structure]菜单(或使用Shift+Ctrl+Alt+S快捷键),打开[Project Structure]窗口.如下图: 2.在[Projec ...