ssm客户管理系统

注意:系统是在实现我的上一篇文章 https://www.cnblogs.com/peter-hao/p/ssm.html的基础上开发

1     需求

1.1   添加客户

客户填写信息,提交,将信息保存到数据库中。

1.2   删除客户

在每条查询出来的客户信息设置删除操作,点击即可删除。更新数据库。

1.3   更新客户信息

在每条查询出来的客户信息设置修改操作,点击进入修改界面,提交,更新数据库。

1.4   查询客户

查询所有的客户信息;根据客户名称进行模糊查询;根据客户类型进行查询。

2     编写思路

从后端向前端开始编写的思路。首先,编写dao层的增删改查的方法,这里大部分利用逆向工程生成的mapper接口中的crud的方法,模糊查询和根据客户类型查询则是重新自定义mapper和xml文件。其次,编写service接口和service实现类,通过spring注解开发,在service实现类中注入mapper接口类,在service实现类中调用mapper中的方法,实现crud操作。然后,开发controller层,注入service接口类,调用service接口中的方法,查询到的数据通过视图解析器解析modelAndView传到jsp界面。修改、删除和更新后通过redirect重定向到查询页面,查看操作后的客户信息。

2.1   dao层

2.1.1  逆向工程中mapper接口中的crud的方法。

运用到逆向工程中mapper接口的以下四个方法:

2.1.2  模糊查询的mapper接口和xml

Mapper接口:

public interface CustomMapper {
public List<HhCustom> findAllCustom(HhCustomVo hhCustomVo)throws Exception;
}

Mapper.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- namespace:命名空间,作用是对sql进行分类化管理,sql隔离 -->
<mapper namespace="cn.haohan.ssm.mapper.CustomMapper">
<sql id="query_custom_where">
<if test="hhCustom!=null">
<if test="hhCustom.name!=null and hhCustom.name!=''">
name like '%${hhCustom.name}%'
</if>
<if test="hhCustom.category!=null and hhCustom.category!=''">
and category = #{hhCustom.category}
</if>
</if>
</sql>
<resultMap type="hhCustom" id="hhCustomResultMap">
<id column="id" property="id"/>
<result column="phone_number" property="phoneNumber"/>
</resultMap>
<select id="findAllCustom" parameterType="cn.haohan.ssm.po.HhCustomVo" resultMap="hhCustomResultMap">
SELECT
* FROM hh_custom
<where>
<include refid="query_custom_where"></include>
</where>
</select>
</mapper>

2.2   service层

2.2.1  service接口

public interface CustomService {
//根据客户id查询
public HhCustom findCustomById(Integer id)throws Exception;
//模糊查询客户信息
public List<HhCustom> findAllCustom(HhCustomVo hhCustomVo)throws Exception;
//根据客户id删除客户
public void deleteCustomById(Integer id)throws Exception;
//添加用户
public void addCustom(HhCustom hhCustom)throws Exception;
//更新用户信息
public void updateCustom(Integer id,HhCustom hhCustom)throws Exception;
}

2.2.2  service实现类

public class CustomServiceImpl implements CustomService{

   @Autowired
HhCustomMapper hhCustomMapper; @Autowired
CustomMapper customMapper; @Override
public HhCustom findCustomById(Integer id) throws Exception {
return hhCustomMapper.selectByPrimaryKey(id);
} @Override
public List<HhCustom> findAllCustom(HhCustomVo hhCustomVo) throws Exception {
return customMapper.findAllCustom(hhCustomVo);
} @Override
public void deleteCustomById(Integer id) throws Exception {
int row = hhCustomMapper.deleteByPrimaryKey(id);
} @Override
public void addCustom(HhCustom hhCustom) throws Exception {
hhCustomMapper.insertSelective(hhCustom);
} @Override
public void updateCustom(Integer id, HhCustom hhCustom) throws Exception {
hhCustom.setId(id);
hhCustomMapper.updateByPrimaryKeySelective(hhCustom);
}
}

2.3   controller层

@Controller
public class CustomController { @Autowired
CustomService customService; // 客户分类
// customTypes表示最终将方法返回值放在request域中的key
@ModelAttribute("customTypes")
public Map<String, String> getcustomTypes() {
Map<String, String> customTypes = new HashMap<String, String>();
customTypes.put("101", "普通客户");
customTypes.put("102", "意向客户");
customTypes.put("103", "活跃客户");
customTypes.put("104", "Vip客户");
return customTypes;
} // 模糊查询客户
@RequestMapping("/findAllCustom")
public ModelAndView findAllCustom(HhCustomVo hhCustomVo) throws Exception {
List<HhCustom> customlist = customService.findAllCustom(hhCustomVo);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("customlist", customlist);
modelAndView.setViewName("customlist");
return modelAndView;
} // 根据客户id查询
@RequestMapping("/findCustomByid")
public ModelAndView findCustomByid(Integer id) throws Exception {
HhCustom hhCustom = customService.findCustomById(id);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("hhCustom", hhCustom);
modelAndView.setViewName("customlist");
return modelAndView;
} // 添加客户
// String返回逻辑视图名,在springmvc中配置的视图解析器中配置jsp文件前后缀
@RequestMapping("/addCustom")
public String addCustom() throws Exception {
return "add_custom";
} // 添加客户submit
@RequestMapping("/addCustomSubmit")
public String addCustomSubmit(HhCustom hhCustom) throws Exception {
customService.addCustom(hhCustom);
// 重定向
return "redirect:findAllCustom.action";
} // 删除客户
@RequestMapping("/deleteCustom")
public String deleteCustom(Integer id) throws Exception {
customService.deleteCustomById(id);
return "redirect:findAllCustom.action";
} // 更新客户信息
@RequestMapping("/updateCustom")
public String updateCustom(Model model, Integer id) throws Exception {
HhCustom hhCustom = customService.findCustomById(id);
model.addAttribute("hhCustom", hhCustom);
return "update_custom";
} // 更新客户信息submit
@RequestMapping("/updateCustomSubmit")
public String updateCustomSubmit(Integer id, HhCustom hhCustom) throws Exception {
customService.updateCustom(id, hhCustom);
return "redirect:findAllCustom.action";
}
}

2.4   jsp界面

2.4.1  customlist.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function addCustom(){
document.customForm.action="${pageContext.request.contextPath}/addCustom.action";
document.customForm.submit();
}
</script>
<title>客戶列表</title>
</head>
<body>
<form name="customForm"
action="${pageContext.request.contextPath}/findAllCustom.action" method="post">
查询条件:
<table width="100%" border=1>
<tr>
<td>客戶名称:<input name="hhCustom.name" />
</td>
<td>客戶类型: <select name="hhCustom.category">
<option selected="selected"></option>
<c:forEach items="${customTypes}" var="customType">
<option value="${customType.value }">${customType.value}</option>
</c:forEach>
</select>
</td>
<td><button type="submit" value="查询" >查询</button></td>
<td><input type="button" value="添加客户" onclick="addCustom()"/></td>
</tr>
</table>
客戶列表:
<table width="100%" border=1>
<tr>
<!-- <th>选择</th> -->
<th>客戶名称</th>
<th>客戶邮箱</th>
<th>客戶电话</th>
<th>客户类型</th>
<th>操作</th>
</tr>
<c:forEach items="${customlist}" var="custom">
<tr>
<%-- <td><input type="checkbox" name="custom_id" value="${custom.id}" /></td> --%>
<td>${custom.name }</td>
<td>${custom.mail }</td>
<td>${custom.phoneNumber }</td>
<td>${custom.category }</td>
<%--<td><fmt:formatDate value="${custom.birthday }" pattern="yyyy-MM-dd HH:mm:ss"/></td>--%>
<td><a href="${pageContext.request.contextPath }/updateCustom.action?id=${custom.id }">修改</a>
<a href="${pageContext.request.contextPath }/deleteCustom.action?id=${custom.id }">删除</a>
</td>
</tr>
</c:forEach>
</table>
</form>
</body>
</html>

2.4.2  add_custom.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加客户</title>
</head>
<body>
<form id="customForm" action="${pageContext.request.contextPath}/addCustomSubmit.action" method="post">
添加客户信息:
<table width="100%" border=1>
<tr>
<td>客户名称</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td>客户邮箱</td>
<td><input type="text" name="mail" /></td>
</tr>
<tr>
<td>客户电话号码</td>
<td><input type="text" name="phoneNumber" /></td>
</tr>
<tr>
<td>客户类型</td>
<td><select name="category">
<c:forEach items="${customTypes}" var="customType">
<%-- <option value="${customType.key }">${customType.value}</option> --%>
<option value="${customType.value }">${customType.value}</option>
</c:forEach>
</select>
</td>
</tr>
</table>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>

2.4.3  update_custom.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改客户信息</title>
</head>
<body>
<form id="customForm" action="${pageContext.request.contextPath}/updateCustomSubmit.action"
method="post">
<input type="hidden" name="id" value="${hhCustom.id }" /> 修改客户信息:
<table width="100%" border=1>
<tr>
<th>客户名称</th>
<td><input type="text" name="name" value="${hhCustom.name }" /></td>
</tr>
<tr>
<td>客户邮箱</td>
<td><input type="text" name="mail" value="${hhCustom.mail }" /></td>
</tr>
<tr>
<td>客户电话号码</td>
<td><input type="text" name="phoneNumber"
value="${hhCustom.phoneNumber }" /></td>
</tr>
<tr>
<td>客户类型</td>
<td><select name="category">
   <c:forEach items="${customTypes}" var="customType">
<%-- <option value="${customType.key }">${customType.value}</option> --%>
<c:if test="${hhCustom.category==customType.value }">
<option value="${customType.value }" selected="selected">${customType.value }</option>
</c:if>
<option value="${customType.value }" >${customType.value}</option>
</c:forEach>
</select></td>
<%-- <td><input type="text" name="category" value="${hhCustom.category }"/></td> --%>
</tr>
</table>
<input type="submit" value="提交">
</form>
</body>
</html>

3     视图展示

3.1   查询

3.2   模糊查询

模糊查询加客户类型

3.3   添加

3.4   修改

3.5   删除

ssm客户管理系统的设计与实现的更多相关文章

  1. 黑马客户管理系统(SSM)

    黑马客户管理系统 1系统概述 1.1系统功能介绍 本系统后台使用SSM框架编写,前台页面使用当前主流的Bootstrap和jQuery框架完成页面信息展示功能(关于Bootstrap的知识,有兴趣的读 ...

  2. 基于ssm的客户管理系统

    查看更多系统:系统大全,课程设计.毕业设计,请点击这里查看 01 概述 一个简单的客户关系管理系统 管理用户的基本数据 客户的分配 客户的流失 已经客户的状态 02 技术 ssm + jdk1.8 + ...

  3. 关于其它模块的设计,有非常多须要自己去构建和完毕,在这里就简单地举几个样例来看看其它模块的设计。我们要做的就是有更改password模块,客户选择模块和关于本软件模块。更改password模块用来更改管理员的password,客户选择对话框模块用来选择已加入的客户,关于本软件模块用来说明客户管理系统的一些必要信息和制作人的信息。

            五,其它模块设计         关于其它模块的设计,有非常多须要自己去构建和完毕,在这里就简单地举几个样例来看看其它模块的设计. 我们要做的就是有更改password模块.客户选择模 ...

  4. (MVC — — Demo)客户管理系统的开发日志

    点击一下 目录 第一步:搭建开发环境 第二步:层次包(按照三层架构思想写) 第四步:开发(utils)工具包 第四步:开发 Dao 层 第五步:开发 services 层 第六步:开发 factory ...

  5. 会员管理系统的设计和开发(2)-- RDLC报表的设计及动态加载

    在上篇<会员管理系统的设计和开发(1)>介绍了关于会员系统的一些总体设计思路和要点,经过一段时间开发,软件终于完成并发布.在这期间,碰到了不少技术难点,并积累了不少开发心得和经验,本篇继续 ...

  6. 开源软件项目管理系统招设计/开发。。。。。Zend Framework2架构 svn://735.ikwb.com/pms

    开源软件项目管理系统招设计/开发.....Zend Framework2架构svn://735.ikwb.com/pms

  7. Microsoft-pubs(图书馆管理系统)-数据库设计

    ylbtech-DatabaseDesgin:微软提供-pubs(图书馆管理系统)-数据库设计   1.A,数据库关系图 1.B,数据库设计脚本 -- ======================== ...

  8. 20160410javaweb 开发小案例 --客户管理系统

    客户管理系统---体验基于数据库javaweb的增删改查 添加客户 查询客户列表 修改客户信息 删除客户 条件查询客户信息 分页查询客户 javaee的经典三层架构--工厂类实现解耦 jsp+serv ...

  9. mongodb入门级的视频教程-简易客户管理系统制作

    本套教程作为mongodb入门级的视频教程,首先讲解了mongodb的下载.安装,环境变量的设置.启动mongodb和将mongodb安装成为windows服务.然后进一步讲解了mongodb里面集合 ...

随机推荐

  1. HTML 学习笔记 day one

    HTML学习笔记 day one Chapter one 网站开发基础 1.2网站的基本架构 网站的基本要素:内容,页面,超链接 动态网页和静态网页的区别在于:动态网页会自动更新,后缀名是.asp或者 ...

  2. SOFA 源码分析— 事件总线

    前言 大部分框架都是事件订阅功能,即观察者模式,或者叫事件机制.通过订阅某个事件,当触发事件时,回调某个方法.该功能非常的好用,而 SOFA 内部也设计了这个功能,并且内部大量使用了该功能.来看看是如 ...

  3. python爬虫入门(二)Opener和Requests

    Handler和Opener Handler处理器和自定义Opener opener是urllib2.OpenerDirector的实例,我们之前一直在使用urlopen,它是一个特殊的opener( ...

  4. HTML语义化基础

    body { background-color: rgb(60,60,60) } 为使页面呈现较好的内容结构,所以对网页进行布局时,将页面相关元素集中在一起,形成页眉.文章.页脚.侧边栏等元素块,刚开 ...

  5. C#现代代码风格指南

    参考资料: asp.net 主页仓库 代码风格 -- 一般原则 最通用的指导原则是我们使用所有的VS默认设置的代码格式,除了我们把系统命名空间放在其他命名空间之前(这在VS中是默认的,但是在VS的更新 ...

  6. java 引用数据类型(类)

    我们可以把类的类型为两种: 第一种,Java为我们提供好的类,如Scanner类,Random类等,这些已存在的类中包含了很多的方法与属性,可供我们使用. 第二种,我们自己创建的类,按照类的定义标准, ...

  7. pycharm linux版快捷方式创建

    ****************************pycharm_linux安装and快捷方式创建******************1.下载好安装包之后解压:    tar -xfz 压缩包名 ...

  8. CDN的基本工作过程

    CDN的基本工作过程 使用CDN会极大地简化网站的系统维护工作量,网站维护人员只需将网站内容注入CDN的系统,通过CDN部署在各个物理位置的服务器进行全网分发,就可以实现跨运营商.跨地域的用户覆盖.由 ...

  9. 许式伟:我与Go语言的这十年[转]

    2017-12-18 许式伟 Go中国 2007 年 9 月 20 日,关于设计一门全新语言的讨论正式开始,这门全新的语言,就是后来的 Go.时至今日,Go 语言已经发布到 1.9 版本,走过了整整十 ...

  10. Python并发编程之从生成器使用入门协程(七)

    大家好,并发编程 进入第七篇. 从今天开始,我们将开始进入Python的难点,那就是协程. 为了写明白协程的知识点,我查阅了网上的很多相关资料.发现很难有一个讲得系统,讲得全面的文章,导致我们在学习的 ...