从0开始入门ssm-crm系统实战

喜欢就点个赞呗!
GitHub项目ssm-learn-crm
show me the code and take to me,做的出来更要说的明白

1.1 克隆

git clone https://github.com/buerbl/ssm-learn-crm.git

1. 2 结果

2 分析需求

我们需要做一个客户系统,使用者可以在系统上面保存、编辑、删除、客户信息。

3 技术选型

这次我们选择 ssm 三大框架搭建系统的后端,前端页面的话用 JSP 以及 JQuery EasyUI;数据库使用 MySQL;项目构想使用 Maven 工具。

技术 作用
Spring 管理对象,管理事务等
SpringMVC 路径跳转,请求访问等
Mybatis 数据获取等
JQuery EasyUI 页面展示等
MySQL 存取数据等
IDEA 快速写代码等
Navicat 数据库可视化软件

4 数据库

我们需要保存客户的名字、性别、联系方式和地址,因此我们的数据库脚本如下

CREATE table t_customer(
    id int PRIMARY KEY auto_increment,
    name VARCHAR(20),
    gender char(1),
    telephone VARCHAR(20),
    address VARCHAR(50)
);

5 Maven 管理

5.1 jar 包

一次性导入我们需要的jar,依赖如下

 <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.4.2</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.3.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.12</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.6.0</version>
        </dependency>
    </dependencies>

5.2 编译问题

可能当我们编译的时候,我们发现 webapp 的文件并没有编译进来,我们需要在 pom.xml 中加入如下,告诉 Mavne 需要编译特定文件。

<build>
   <resources>
        <resource>
            <directory>src/main/webapp</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

6 划分层次

来到这里的话,我们需要建立文件夹,准备开始写代码。一般按照套路的话,我喜欢如下的规则

文件夹 作用
controller 控制层代码
domain 实体类代码
dao Mapper代码
service 服务层代码

7 实体类代码

我们根据数据库字段编写实体类代码,代码如下,我使用了 lombok 框架,这个东西需要 IDEA 安装一个 lombok 插件。

package com.buer.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @Description:
 * @Author: boolean
 * @Date: 2019/12/22 11:51
 */

@Getter
@Setter
@ToString

@AllArgsConstructor
public class Customer {
    private  Integer id;
    private String name;
    private String gender;
    private String telephone;
    private String address;
}

有个问题,这些字段是怎样和数据库字段一一对应的呢?下面揭晓。

8 Mapper代码

这里我们需要的 Mybatis 要上场了,首先我们需要如下Mapper代码

package com.buer.dao;

import com.buer.domain.Customer;

import java.util.List;

public interface CustomerMapper {
    /**
     * 添加客户
     */
    void saveCustomer(Customer customer);

    /**
     * 查询所有客户
     * @return
     */
    List<Customer> list();

    /***
     * 查找某个客户
     * @param id
     * @return
     */
    Customer findById(Integer id);
}

9 Mapper 对应的 xml

有了 Mapper 代码,我们需要给 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">
<!-- 该文件编写mybatis中的mapper接口里面的方法提供对应的sql语句 -->
<mapper namespace="com.buer.dao.CustomerMapper">

    <!-- 添加客户 -->
    <insert id="saveCustomer" parameterType="com.buer.domain.Customer">
        INSERT INTO ssm.t_customer
            (
            NAME,
            gender,
            telephone,
            address
            )
            VALUES
            (
            #{name},
            #{gender},
            #{telephone},
            #{address}
            )
    </insert>

    <select id="list" resultType="com.buer.domain.Customer">
        select * from t_customer
    </select>

    <select id="findById" resultType="com.buer.domain.Customer">
        select * from t_customer where id = #{id}
    </select>
</mapper>

解答上面的问题,实体类字段是怎样和数据库字段一一对应,通过 resultType 来自动映射。

10 服务层代码

先来接口层的代码。代码如下

package com.buer.service;

import com.buer.domain.Customer;

import java.util.List;

public interface IcustomerService {
    /**
     * 添加客户
     */
    void saveCustomer(Customer customer);

    /**
     * 返回所有数据
     * @return
     */
    List<Customer> list();

    /**
     * 修数据
     * @return
     */
    Customer findById(Integer id);
}

然后实现接口,代码如下

package com.buer.service.Impl;

import com.buer.dao.CustomerMapper;
import com.buer.domain.Customer;
import com.buer.service.IcustomerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: boolean
 * @Date: 2019/12/22 18:28
 */
@Service("customerService")
public class IcustomerServiceImpl implements IcustomerService {
    @Resource
    private CustomerMapper customerMapper;
    @Override
    @Transactional
    public void saveCustomer(Customer customer) {
        customerMapper.saveCustomer(customer);
    }

    @Override
    public List<Customer> list() {
        return customerMapper.list();
    }

    @Override
    public Customer findById(Integer id) {
        return customerMapper.findById(id);
    }
}

这里我们看到@Service("customerService"),@Resource, @Transactional,这些注解他们的作用是啥子哦?请看下面

注解 作用
@Service("customerService") 告诉 Spring, 这是一个叫 customerService 的东西,你要照顾好她,给他在初始化的时候创建一个对象。
@Resource Java里面的注解,注入对象
@Transactional 告诉 Spring,需要开始事务

11 控制层代码

这里就是 SpringMVC 的舞台了。代码如下

package com.buer.controller;

import com.buer.domain.Customer;
import com.buer.service.IcustomerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: boolean
 * @Date: 2019/12/22 18:50
 */

@Controller
@RequestMapping("/customer")
public class CustomerController {

    @Resource
    private IcustomerService service;
    @RequestMapping("/index")
    public String test(){
        System.out.println("ssss");
        return "index";
    }

    @RequestMapping("/save")
    public String save(Customer customer){
        System.out.println("save");
        service.saveCustomer(customer);
        return "success";
    }

    @RequestMapping("/list")
    @ResponseBody
    public List<Customer> list(){
        System.out.println("list");
        return service.list();
    }

    @RequestMapping("/findById")
    @ResponseBody
    public Customer findById(Integer id){
        System.out.println("findById");
        return service.findById(id);
    }
}
注解 作用
@Controller 告诉 SpringMVC, 这是你负责的代码
@RequestMapping("/save") 告诉 SpringMVC,用 “/save”路径访问
@ResponseBody 告诉 SpringMVC,需要返回JSON

以上就是代码的编写,但是还没有完成哈,我们需要一些配置文件。

12 jdbc.properties

我们要连接数据库,代码如下

jdbc.url=jdbc:mysql://localhost:3306/ssm
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.user=root
jdbc.password=123456

13 applicationContext.xml

我们要告诉 Spring 连接数据库,以及我们写的代码在哪里,怎么去操作我们的代码。代码如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- 读取jdbc.properties -->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!-- 创建DataSource -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="url" value="${jdbc.url}"/>
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="username" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="maxActive" value="10"/>
        <property name="maxIdle" value="5"/>
    </bean>

    <!-- 创建SqlSessionFactory对象 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 关联连接池 -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 加载mapper.xml -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    </bean>
    <!-- Mapper所有接口的扫描 -->
    <!--注意:如果使用Mapper接口包扫描,那么每个Mapper接口在Spring容器中的id名称为类名: 例如 CustomerMapper -> customerMapper-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 配置Mapper接口所在包路径  -->
        <property name="basePackage" value="com.buer.dao"></property>
    </bean>

    <!-- 开启Spring的IOC注解扫描 -->
    <context:component-scan base-package="com.buer"/>

    <!-- 开启Spring的事务 -->
    <!-- -事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 启用Spring事务注解 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

</beans>

14 spring-mvc.xml

我们需要告诉 SpringMVC,他需要的代码在哪里,怎么去操作我们的代码

15 web.xml

我们需要启动项目了,以及一些字体指定。代码如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>01.mybatis</display-name>
  <!-- 配置SpringMVC编码过滤器 -->
  <filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>utf-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- 启动SpringMVC -->
  <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 参数:读取spring-mvc.xml -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.action</url-pattern>
  </servlet-mapping>

  <!-- 启动spring -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 修改路径 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
</web-app>

这里的话,后端就搭起来了。

16 页面编写

16.1 index.jsp

我们需要编写首页,代码如下

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>booleanbl 公众号 客户关系管理系统</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <link id="themeLink" rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">

    <style type="text/css">
        ul{
            line-height: 30px;
        }
    </style>
  </head>

  <body class="easyui-layout">
     <!-- 顶部 -->
    <div data-options="region:'north',split:true" style="height:80px;">

        <!-- logo -->
        <div id="logo">
            <img src="images/20191223003101.png"/>
        </div>

        <!-- 登录用户信息 -->
        <div id="loginDiv" style="position: absolute;right: 20px;top: 20px;">
             欢迎你,[超级管理员],你使用[192.156.21.22]IP登录!
        </div>

        <div id="themesDiv" style="position: absolute;right: 20px;top:40px;">
            <a href="javascript:void(0)" id="mb" class="easyui-menubutton"
                    data-options="menu:'#Themesmeus',iconCls:'icon-edit'">切换风格</a>
            <div id="Themesmeus" style="width:150px;">
                <div>default</div>
                <div>gray</div>
                <div>black</div>
                <div>bootstrap</div>
                <div>material</div>
                <div>metro</div>
            </div>
        </div>
    </div>   

    <!-- 底部 -->
    <div data-options="region:'south',split:true" style="height:30px;">
        <div id="copyrightDiv" style="text-align: center;">
            booleanbl出品&copy;2018版权所有
        </div>
    </div>   

     <!-- 左边系统菜单 -->
    <div data-options="region:'west',title:'系统菜单',split:true" style="width:200px;">
        <div id="aa" class="easyui-accordion" style="width:193px;" data-options="border:0,multiple:true" >   

            <div title="系统管理" data-options="iconCls:'icon-reload',selected:true" style="padding:10px;">
               <ul>
                 <li><a href="javascript:void(0)" pageUrl="customer_manage.jsp">客户管理</a></li>
               </ul>
            </div>
        </div>
    </div>   

    <!-- 中间编辑区域 -->
    <div data-options="region:'center'" style="padding:5px;background:#eee;">
        <div id="tt" class="easyui-tabs" style="width:500px;height:250px;" data-options="fit:true">
            <div title="起始页" style="padding:20px;display:none;">
               欢迎登录booleanbl客户关系管理系统
            </div>
        </div>
    </div> 

    <script type="text/javascript">
        $(function(){
            //给a标签绑定时间
            $("a[pageUrl]").click(function(){
                //1.获取pageUrl属性值(需要跳转的页面地址)
                var pageUrl = $(this).attr("pageUrl");
                //获取a标签的内容,标题
                var title = $(this).text();

                //2.判断是否存在指定标题的选项卡
                if( $("#tt").tabs("exists",title)  )  {
                    //3.如果存在,则选项该选项卡
                    $("#tt").tabs("select",title);
                }else{
                    //4.如果不存在,则添加选项卡
                    $("#tt").tabs("add",{
                        title:title,
                        content:"<iframe src='"+pageUrl+"' width='100%' height='100%' frameborder='0'><iframe>",
                        closable:true
                    });
                }
            });

            //点击切换模块菜单的时候,进行切换模块
            $("#Themesmeus").menu({
                onClick:function(item){
                    //1.获取需要改变的模块名称
                    var themeName = item.text;

                    //2.获取link标签的href属性
                    var href= $("#themeLink").attr("href");

                    //3.更改href的属性值
                    // easyui/themes/default/easyui.css
                    href = href.substring(0,href.indexOf("themes"))+"themes/"+themeName+"/easyui.css";

                    //4.更新link的href属性
                    $("#themeLink").attr("href",href);
                }
            });
        });

    </script>
  </body>
</html>

16.2 customer_manage.jsp

我们需要详情页,代码如下

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>客户管理</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!-- 导入easyui的资源文件 -->
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <link id="themeLink" rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
  </head>

  <body>
    <table id="list"></table>

    <!-- 工具条 -->
    <div id="tb">
        <a id="addBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a>
        <a id="editBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
        <a id="deleteBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
    </div>

    <!-- 编辑窗口 -->
    <div id="win" class="easyui-window" title="客户数据编辑" style="width:500px;height:300px"
        data-options="iconCls:'icon-save',modal:true,closed:true">
        <form id="editForm" method="post">
            <%--提供id隐藏域 --%>
            <input type="hidden" name="id">
            客户姓名:<input type="text" name="name" class="easyui-validatebox" data-options="required:true"/><br/>
            客户性别:
            <input type="radio" name="gender" value="男"/>男
            <input type="radio" name="gender" value="女"/>女
            <br/>
            客户手机:<input type="text" name="telephone" class="easyui-validatebox" data-options="required:true"/><br/>
            客户住址:<input type="text" name="address" class="easyui-validatebox" data-options="required:true"/><br/>
        <a id="saveBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>
     </form>
    </div>  

    <script type="text/javascript">
        $(function(){
            $("#list").datagrid({
                //url:后台数据查询的地址
                url:"customer/list.action",
                //columns:填充的列数据
                    //field:后台对象的属性
                    //tille:列标题
                columns:[[
                    {
                        field:"id",
                        title:"客户编号",
                        width:100,
                        checkbox:true
                    },
                    {
                        field:"name",
                        title:"客户姓名",
                        width:200
                    },
                    {
                        field:"gender",
                        title:"客户性别",
                        width:200
                    },
                    {
                        field:"telephone",
                        title:"客户手机",
                        width:200
                    },
                    {
                        field:"address",
                        title:"客户住址",
                        width:200
                    }
                ]],
                //显示分页
                pagination:true,
                //工具条
                toolbar:"#tb"
            });

            //打开编辑窗口
            $("#addBtn").click(function(){
                //清空表单数据
                $("#editForm").form("clear");
                $("#win").window("open");
            });

            //保存数据
            $("#saveBtn").click(function(){
                $("#editForm").form("submit",{
                    //url: 提交到后台的地址
                    url:"customer/save.action",
                    //onSubmit: 表单提交前的回调函数,true:提交表单   false:不提交表单
                    onSubmit:function(){
                        //判断表单的验证是否都通过了
                        return $("#editForm").form("validate");
                    },
                    //success:服务器执行完毕回调函数
                    success:function(data){ //data: 服务器返回的数据,类型字符串类
                        //要求Controller返回的数据格式:
                        //成功:{success:true} 失败:{success:false,msg:错误信息}

                        //把data字符串类型转换对象类型
                        data = eval("("+data+")");

                        if(data.success){
                            //关闭窗口
                            $("#win").window("close");
                            //刷新datagrid
                            $("#list").datagrid("reload");

                            $.messager.alert("提示","保存成功","info");
                        }else{
                            $.messager.alert("提示","保存失败:"+data.msg,"error");
                        }
                    }
                });

            });

            //修改数据
            $("#editBtn").click(function(){
                //判断只能选择一行
                var rows = $("#list").datagrid("getSelections");
                if(rows.length!=1){
                    $.messager.alert("提示","修改操作只能选择一行","warning");
                    return;
                }

                //表单回显
                $("#editForm").form("load","customer/findById.action?id="+rows[0].id);

                $("#win").window("open");
            });

            //删除
            $("#deleteBtn").click(function(){
                var rows =$("#list").datagrid("getSelections");
                if(rows.length==0){
                    $.messager.alert("提示","删除操作至少选择一行","warning");
                    return;
                }

                //格式: id=1&id=2&id=3
                $.messager.confirm("提示","确认删除数据吗?",function(value){
                    if(value){
                        var idStr = "";
                        //遍历数据
                        $(rows).each(function(i){
                            idStr+=("id="+rows[i].id+"&");
                        });
                        idStr = idStr.substring(0,idStr.length-1);

                        //传递到后台
                        $.post("customer/delete.action",idStr,function(data){
                            if(data.success){
                                //刷新datagrid
                                $("#list").datagrid("reload");

                                $.messager.alert("提示","删除成功","info");
                            }else{
                                $.messager.alert("提示","删除失败:"+data.msg,"error");
                            }
                        },"json");
                    }
                });
            });
        });

    </script>
  </body>
</html>

完成

常见问题

java-lang-illegalargumentexception-no-converter-found-for-return-value-of-type

原因是没有转换json返回

  1. 在 CustomerController 上添加 @ResponseBody
  2. 需要添加 jackson 依赖

原文地址:https://www.cnblogs.com/chenzhuantou/p/12092781.html

时间: 2024-08-09 20:23:49

从0开始入门ssm-crm系统实战的相关文章

(十)Unity5.0新特性------新UI系统实战

原文 Unity New GUI Tutorial – Part 1 Unity New GUI Tutorial- Part 2 Unity New GUI Tutorial – Part 3 大家可以看看他的游戏源代码,然后了解一下新UI的使用.  介绍的很详细: 需要指出的 UI的动画都是使用 Animator\Animation组件实现,在实际的项目开发中,会使用Dotween\  Dftween这些补间动画插件来实现.   用代码通知,更加灵活. 但是使用 Animator\Anima

Extjs5.0从入门到实战开发信息管理系统(Extjs基础、Extjs5新特性、Spring、Spring mvc、Mybatis)视频教程

Extjs5.0从入门到实战开发信息管理系统(Extjs基础.Extjs5新特性.Spring.Spring mvc.Mybatis)视频教程下载   联系QQ:1026270010 Extjs作为一款优秀的JS前端开发框架以其良好的架构.丰富的UI组件库.完善的文档和社区支持等诸多优点拥有广泛的市场应用空间,开发人员无需过多的关注HTML.CSS甚至各种常用JS算法,只需把精力放在业务逻辑上,利用各种组件的相互组合调用便可轻松而高效的开发出系统的前端页面. Extjs5在之前版本的基础上又推出

Asp.Net MVC4.0 从入门到精通与项目实战 (Petapoco框架、二维码自定义、Bootstrap视图)视频教程

Asp.Net MVC4.0 从入门到精通与项目实战 (Petapoco框架.二维码自定义.Bootstrap视图)视频教程下载    联系QQ:1026270010 Asp.Net MVC 简介      MVC模式是“Model-View-Controller”的缩写,中文翻译为“模式-视图-控制器”.MVC模式是于20世纪70年代在smaltalk80的GUI设计中被提出的.它包括3个部分:模型(Model).视图(View)和控制器(Controller).MVC模式至今已被广泛使用,A

Extjs视频教程_Extjs5.0从入门到实战开发信息管理系统

Extjs5.0从入门到实战开发信息管理系统(Extjs基础.Extjs5新特性.Spring.Spring mvc.Mybatis)适合人群:初级课时数量:40课时用到技术:Extjs基础,Extjs5新特性,sencha cmd,spring,spring mvc, mybatis涉及项目:信息管理系统核心框架(mvvm+mvc架构)咨询qq:1840215592课程内容简介:1.课程研发环境开发工具:eclipse,sencha cmd:数据库工具:mysql5,mysql workben

Spark2.0从入门到精通:Scala编程、大数据开发、上百个实战案例、内核源码深度剖析视频教程

38套大数据,云计算,架构,数据分析师,Hadoop,Spark,Storm,Kafka,人工智能,机器学习,深度学习,项目实战视频教程 视频课程包含: 38套大数据和人工智能精品高级课包含:大数据,云计算,架构,数据挖掘实战,实时推荐系统实战,电视收视率项目实战,实时流统计项目实战,离线电商分析项目实战,Spark大型项目实战用户分析,智能客户系统项目实战,Linux基础,Hadoop,Spark,Storm,Docker,Mapreduce,Kafka,Flume,OpenStack,Hiv

Java高级项目实战之CRM系统用户登录功能实现

用户登录功能后台代码实现: UserMapper接口查询方法定义 /** * * @param userName * @param userPwd * @param roleName * 查询用户记录 * @return */ User queryUser(@Param("userName")String userName); <!-- 查询用户 --> <select id="queryUser" resultMap="BaseResu

MongoDB入门必读(概念与实战并重)

MongoDB入门必读(概念与实战并重) 一.概述 MongoDB是一个基于分布式文件存储的数据库开源项目.由C++语言编写.旨在为WEB应用提供可护展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似json的bjson格式,因此可以存储比较复杂的数据类型.Mongo最大的特点是他支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝

《黑客攻防技术-系统实战》第二章--栈溢出4

参考文献: https://en.wikipedia.org/wiki/Buffer_overflow_protectionhttps://www.zhihu.com/question/20871464/answer/18743160http://www.ibm.com/developerworks/cn/linux/l-cn-gccstack/ <黑客攻防技术宝典-系统实战> ..........................................................

Java秒杀系统实战系列~商品秒杀代码实战

摘要: 本篇博文是"Java秒杀系统实战系列文章"的第六篇,本篇博文我们将进入整个秒杀系统核心功能模块的代码开发,即"商品秒杀"功能模块的代码实战. 内容: "商品秒杀"功能模块是建立在"商品详情"功能模块的基础之上,对于这一功能模块而言,其主要的核心流程在于:前端发起抢购请求,该请求将携带着一些请求数据:待秒杀Id跟当前用户Id等数据:后端接口在接收到请求之后,将执行一系列的判断与秒杀处理逻辑,最终将处理结果返回给到前端.

Java秒杀系统实战系列~分布式唯一ID生成订单编号

摘要: 本篇博文是"Java秒杀系统实战系列文章"的第七篇,在本博文中我们将重点介绍 "在高并发,如秒杀的业务场景下如何生成全局唯一.趋势递增的订单编号",我们将介绍两种方法,一种是传统的采用随机数生成的方式,另外一种是采用当前比较流行的"分布式唯一ID生成算法-雪花算法"来实现. 内容: 在上一篇博文,我们完成了商品秒杀业务逻辑的代码实战,在该代码中,我们还实现了"当用户秒杀成功后,需要在数据库表中为其生成一笔秒杀成功的订单记录&qu