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. Python控制台输出时刷新当前行内容而不是输出新行

    需求目标 执行Python程序的时候在控制台输出内容的时候固定一刷新内容,如下: Downloading File FooFile.txt [%] 而不是 Downloading File FooFi ...

  2. How to delete System Profiles for those registered with Red Hat Subscription Management (RHSM)?

    Environment Red Hat Customer Portal Certificate Based Subscription Red Hat Subscription Management ( ...

  3. 状压dp,松鼠从起点出发,拿到所有坚果,然后返回起点,求最短时间。

    UVA10944 松鼠从起点出发,拿到所有坚果,然后返回起点,求最短时间. #include<iostream> #include<cstdio> #include<al ...

  4. ArcGIS Python 保存lyr

    import arcpy ##################my = arcpy.GetParameterAsText(0)mylyrfile = arcpy.GetParameterAsText( ...

  5. 使用 usb 调试的时候,连接上电脑没反应

    使用 usb 调试的时候,连接上电脑没反应 原因: 手机上没有信任本计算机的授权,请在手机上信任该授权 解决方法: 原因就是手机上会有一个弹话框,让我们信任该计算机,我们才可以进行 usb调试 我们的 ...

  6. linux下如何单独编译设备树?

    答: make <vendor>/<device_name>.dtb 如: make freescale/fsl-1043a-rdb.dtb

  7. 软件-设计-Adobe-Adobe XD:百科

    ylbtech-软件-设计-Adobe-Adobe XD:百科 创建线框.设计.创建原型.展示以及共享适用于 Web.移动设备和语音等的卓越体验 - 以上操作在一款应用程序中即可完成.XD 面向需要进 ...

  8. Python3+RobotFramewok 用户自定义库的开发(四)

    在介绍这个之前,可以先看下python的目录Python\Lib\site-packages下面的文件夹,你会发现这个目录下面有DatabaseLibrary.RequestsLibrary.Sele ...

  9. 一百二十六:CMS系统之轮播图管理页面布局和添加轮播图的模态对话框制作

    视图 @bp.route('/banners/')@login_required@permission_required(CMSPersmission.POSTER)def banners(): re ...

  10. ping指定IP的指定端口号

    ping是简单的测试网络连接情况的小工具,对于一般用户很实用,但是ping有个缺点就是,不能指定端口 tcping命令是针对tcp监控的,也可以看到ping值,即使源地址禁ping也可以通过tcpin ...