(ps:前两章我们已经把管理员登录和查看用户的功能实现了,那么今天我们将要实现:添加用户,删除用户,和修改用户功能)

由于Cusomer的POJO类型已经写好了,所以这次我们之前从CustomerController下手!!!

添加用户功能

①在CutsomerController类中编写customerCreate方法,并在方法名上头写上请求映射路径(@RequestMapping("/customer/create.action")) ,和@ResponseBody。

②在customerCreate方法中先获取用户session,然后将当前用户id存储在客户对象中,然后调用customer.setCust_create_id()方法将当前用户id存储在客户对象中,接着为了得到mysql里面的时间戳,我们用了Timestamp对象获取一个yyyy/MM/dd
HH:mm:ss
的时间格式,然后将这个Timestamp对象装载到customer.setCust_createtime()方法中,最后再判断Service层中受影响的行数来判断是否创建用户成功,这样我们CustomerController中的创建客户就写完了,还记得第二章教程中的流程图吗?现在我们就得去Service层中编写接口,并实现接口类。

③在CustomerService接口中创建createCustomer方法(注意此处的返回值类型是int类型),然后去CustomerServiceImpl实现类中实现该接口方法。

④在CustomerDao接口中也同样编写createCustomer方法,然后在CustomerDao.xml中编写添加客户的sql语句,代码如下:

<!-- 添加客户 -->
<insert id="createCustomer" parameterType="customer">
insert into customer(
cust_name,
cust_user_id,
cust_create_id,
cust_source,
cust_industry,
cust_level,
cust_linkman,
cust_phone,
cust_mobile,
cust_zipcode,
cust_address,
cust_createtime
)
values(#{cust_name},
#{cust_user_id},
#{cust_create_id},
#{cust_source},
#{cust_industry},
#{cust_level},
#{cust_linkman},
#{cust_phone},
#{cust_mobile},
#{cust_zipcode},
#{cust_address},
#{cust_createtime}
)
</insert>

⑤写到这里,我们的添加用户的功能就写完了。回顾一下我们是怎么写的:"首先我们是从CustomerController下手的!在该方法中我们创建了createCustomer方法,然后再到Service层中编写createCustomer该接口方法,然后让CustomerServiceImpl实现类去实现它,最后在回到CustomerDao中创建同样的方法,然后重点是在CustomerDao.xml中的sql语句"。

更新用户功能,删除用户功能

           经过之前查看用户和创建用户功能,相信大家对SSM框架的运用已经了如指掌了,那么省下的两个功能,我将Controller和sql的代码粘贴到这,其他的大家自己写写试试,写不出来也没关系,源码已经分享到CSDN上了,待会会把网址贴在文章底部。
            Controller:
/*
* 更新客户
*/
@RequestMapping("/customer/update.action")
@ResponseBody
public String customerUpdate(Customer customer)
{
int rows=customerService.updateCustomer(customer);
if(rows>0)
{
return "OK";
}else {
return "FAIL";
}
}
/*
* 删除客户
*/
@RequestMapping("/customer/delete.action")
@ResponseBody
public String customerDelete(Integer id)
{
int rows=customerService.deleteCustomer(id);
if(rows>0)
{
return "OK";
}else {
return "FAIL";
}
}

XML:

<!-- 更新客户 -->
<update id="updateCustomer" parameterType="customer">
update customer
<set>
<if test="cust_name!=null">
cust_name=#{cust_name},
</if>
<if test="cust_user_id!=null">
cust_user_id=#{cust_user_id},
</if>
<if test="cust_create_id!=null">
cust_create_id=#{cust_create_id},
</if>
<if test="cust_source!=null">
cust_source=#{cust_source},
</if>
<if test="cust_industry!=null">
cust_industry=#{cust_industry},
</if>
<if test="cust_level!=null">
cust_level=#{cust_level},
</if>
<if test="cust_linkman!=null">
cust_linkman=#{cust_linkman},
</if>
<if test="cust_phone!=null">
cust_phone=#{cust_phone},
</if>
<if test="cust_mobile!=null">
cust_mobile=#{cust_mobile},
</if>
<if test="cust_zipcode!=null">
cust_zipcode=#{cust_zipcode},
</if>
<if test="cust_address!=null">
cust_address=#{cust_address},
</if>
<if test="cust_createtime!=null">
cust_createtime=#{cust_createtime},
</if>
</set>
where cust_id=#{cust_id}
</update>
<!-- 删除客户 -->
<delete id="deleteCustomer" parameterType="Integer">
delete from customer where cust_id=#{id}
</delete>

源码下载地址: Boot-crm管理系统源码下载

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

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

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

  2. MIP开发教程(三) 使用MIP-CLI工具调试组件

    一 . 在 mip-extensions 仓库中创建新的组件 二 . 预览调试组件 三 . 在 MIP 页中引用自己编写的 MIP 组件 四 . 组件提交到 GitHub 仓库时需要进行校验 站长开发 ...

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

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

  4. Odoo 二次开发教程(三)-第一个Model及Form、Tree视图

    创建完我们的模块,接下来我们就要为我们的模块添加一些对象.今天我们将要创建一个学生对象(tech.student)和一些基本的属性,并将用form和tree视图将其展示出来: 一. 创建tech.st ...

  5. XAF应用开发教程(三)业务对象模型之引用类型与关联关系

    本节介绍信息系统开发中最常见的问题,引用关系,一对多关系,多对多关系. 以客户信息为例,客户通常需要客户分类,如VIP客户,普通客户,潜在客户.当然,我们可以定义枚举类型进行定义出这个类型,并在客户类 ...

  6. Boot-crm管理系统开发教程(二)

    ps:昨天将管理员登录的功能完成了,并完美的解决跳过登录从而进入管理界面的bug,今天我们将实现"查询用户"功能. ①在po包中创建Customer类,并编写相关变量和添加set/ ...

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

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

  8. 微信开放平台 公众号第三方平台开发 教程四 代公众号调用接口的SDK和demo

    原文:微信开放平台 公众号第三方平台开发 教程四 代公众号调用接口的SDK和demo 教程导航: 微信开放平台 公众号第三方平台开发 教程一 平台介绍 微信开放平台 公众号第三方平台开发 教程二 创建 ...

  9. 开发教程(四) MIP组件平台使用说明

    组件审核平台用于上传 MIP 组件.经过自动校验之后,提交审核,通过审核的组件会定时推送到线上,供网站使用. 平台地址:https://www.mipengine.org/platform/ 1. 使 ...

随机推荐

  1. 【洛谷2053】 [SCOI2007]修车(费用流)

    传送门 洛谷 Solution 考虑把每一个修车工人拆成\(n\)个点,那么考虑令\(id(i,j)\)为第\(i\)个工人倒数第\(j\)次修车. 然后就可以直接跑费用流了!!! 代码实现 /* m ...

  2. Map集合循环遍历的几种方式

    package cn.jdbc.test;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import ...

  3. java按某个字段对数据分组

    import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; i ...

  4. centos7搭建hadoop-2.7.3,zookeeper-3.4.6,hbase-1.2.5(root用户)

    环境:[centos7.hadoop-2.7.3.zookeeper-3.4.6.hbase-1.2.5] 两个节点:[主节点,主机名为Master,用户为root:从节点,主机名为Slave,用户为 ...

  5. jquery+ajax 实现搜索框提示

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

  6. FreeMarker学习(常用指令)

    参考:http://freemarker.foofun.cn/dgui_quickstart_basics.html assign: 使用该指令你可以创建一个新的变量, 或者替换一个已经存在的变量 a ...

  7. QT程序拷贝 转移 改变运行环境

    qt程序 在windows平台下怎么运行? 以前开发环境是VS2008编译 +qt-win-opensource-4.7.4-vs2008框架 +QtCreator编辑界面(以前的例子,win7下成功 ...

  8. 【转】Qt编写串口通信程序全程图文讲解

    本文章原创于www.yafeilinux.com 转载请注明出处. (说明:我们的编程环境是windows xp下,在Qt Creator中进行,如果在Linux下或直接用源码编写,程序稍有不同,请自 ...

  9. sql_monitor实时监控

    1 检查数据库是否启用了监控功能 1)检查参数:CONTROL_MANAGEMENT_PACK_ACCES SQL> show parameter CONTROL_MANAGEMENT_PACK ...

  10. springboot发送邮件,以及携带邮件附件简单使用

    可以通过springboot官方文档中Sending Email,找到类似如下java mail的使用文档 https://docs.spring.io/spring/docs/5.1.9.RELEA ...