SSM框架AJAX分页 PageHelper查询,增删改 后端业务逻辑

功能点

  1. 分页
  2. 数据校验:jquery前端校验+JSR303后端校验
  3. ajax
  4. Rest风格的URI;使用HTTP方式的请求动词,来表示对资源的操作
    GET(查询)、POST(新增)、PUT(修改)、DELETE(删除)

技术点:

1. 基础框架--SSM(SpingMVC+Spring+Mybatis)
2.数据库-MySQL
3.前端框架-bootstrop快速搭建简洁美观的界面
4.项目依赖管理-Maven
5.分页-pagehelper
6.逆向工程-Mybatis Generator

AJAX查询

  • index.jsp页面直接发送ajax请求进行员工分页数据的查询
  • 服务器将查询出的数据,以json字符串的形式返回给浏览器
  • 浏览器收到js字符串。可以使用js对json进行解析,使用js通过dom增删改 改变页面
  • 返回json。实现客户端的无关性

新增逻辑

这里写图片描述

修改逻辑

这里写图片描述

删除逻辑

这里写图片描述

附1表结构

部门表

这里写图片描述

员工表

这里写图片描述

附2项目工程目录

这里写图片描述

附3:Mapping层代码

1.部门dao文件

package com.atwolf.crud.dao;

import java.util.List;

import com.atwolf.crud.bean.Department;

public interface DepartmentMapper {
    //按主键ID删除一条数据
    public int deleteByPrimaryKey(Integer deptId);
    //保存全部数据 
    public int insert(Department record);
    //有选择的保存部分数据 
    public int insertSelective(Department record);
    //根据主键查询一条记录
    public Department selectByPrimaryKey(Integer deptId);
    //有选择的更新部分数据
    public int updateByPrimaryKeySelective(Department record);
    //更新全部数据
    public int updateByPrimaryKey(Department record);
    //查询所有
    List<Department>  Depts();
}

2.部门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">
<mapper namespace="com.atwolf.crud.dao.DepartmentMapper">
  <resultMap id="BaseResultMap" type="com.atwolf.crud.bean.Department">
    <id column="dept_id" jdbcType="INTEGER" property="deptId" />
    <result column="dept_name" jdbcType="VARCHAR" property="deptName" />
  </resultMap>
  <sql id="Base_Column_List">
    dept_id, dept_name
  </sql>
  <!--查询所有  -->
  <select id="Depts" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tbl_dept
  </select>
  <!--根据主键查询一条记录  -->
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tbl_dept
    where dept_id = #{deptId,jdbcType=INTEGER}
  </select>
  <!--按主键ID删除一条数据  -->
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from tbl_dept
    where dept_id = #{deptId,jdbcType=INTEGER}
  </delete>
  <!--保存全部数据  -->
  <insert id="insert" parameterType="com.atwolf.crud.bean.Department">
    insert into tbl_dept (dept_id, dept_name)
    values (#{deptId,jdbcType=INTEGER}, #{deptName,jdbcType=VARCHAR})
  </insert>
  <!--有选择的保存部分数据  -->
  <insert id="insertSelective" parameterType="com.atwolf.crud.bean.Department">
    insert into tbl_dept
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="deptId != null">
        dept_id,
      </if>
      <if test="deptName != null">
        dept_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="deptId != null">
        #{deptId,jdbcType=INTEGER},
      </if>
      <if test="deptName != null">
        #{deptName,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <!--有选择的更新部分数据  -->
  <update id="updateByPrimaryKeySelective" parameterType="com.atwolf.crud.bean.Department">
    update tbl_dept
    <set>
      <if test="deptName != null">
        dept_name = #{deptName,jdbcType=VARCHAR},
      </if>
    </set>
    where dept_id = #{deptId,jdbcType=INTEGER}
  </update>
  <!--更新全部数据  -->
  <update id="updateByPrimaryKey" parameterType="com.atwolf.crud.bean.Department">
    update tbl_dept
    set dept_name = #{deptName,jdbcType=VARCHAR}
    where dept_id = #{deptId,jdbcType=INTEGER}
  </update>
</mapper>

3.员工dao文件

package com.atwolf.crud.dao;

import java.util.List;

import com.atwolf.crud.bean.Employee;

public interface EmployeeMapper {
    //ͨ通过主键删除一条记录
    public int deleteByPrimaryKey(Integer empId);
    //批量删除
    public int deleteSelectiveEmp(List<Integer> ids);
    //保存全部数据
    public int insert(Employee record);
    //有选择的保存部分数据
    public int insertSelective(Employee record);
    //查询所有
    public List<Employee> selectByEmployee();
    //ͨ通过主键ID查询数据 
    public Employee selectByPrimaryKey(Integer empId);
    //有选择的更新字段  
    public int updateByPrimaryKeySelective(Employee record);
    //更新全部字段
    public int updateByPrimaryKey(Employee record);
    //多表查询使用:查询员工表的同时,也把部门信息查询出来 
    public Employee selectByPrimaryKeywithDept(Integer empId);
    //多表查询使用:查询员工表的同时,也把部门信息查询出来 
    public List<Employee> selectByEmpWithDept();
    //统计员工表的总记录数
    public List<Employee> selectByCountEmployee(Employee employee);

}

4.员工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">
<mapper namespace="com.atwolf.crud.dao.EmployeeMapper">
  <!--封装Employee组件中的所有字段  -->
  <resultMap id="BaseResultMap" type="com.atwolf.crud.bean.Employee">
    <id column="emp_id" jdbcType="INTEGER" property="empId" />
    <result column="emp_name" jdbcType="VARCHAR" property="empName" />
    <result column="gender" jdbcType="CHAR" property="gender" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="d_id" jdbcType="INTEGER" property="dId" />
  </resultMap>
  <!--多表查询使用:查询员工表的同时,也把部门信息查询出来  -->
  <!--封装多表查询中Employee组件中的字段  -->
  <resultMap id="WithDept" type="com.atwolf.crud.bean.Employee">
    <id column="emp_id" jdbcType="INTEGER" property="empId" />
    <result column="emp_name" jdbcType="VARCHAR" property="empName" />
    <result column="gender" jdbcType="CHAR" property="gender" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="d_id" jdbcType="INTEGER" property="dId" />
    <!--在Employee组件中封装一个部门信息,如何封装       -->
    <association property="department" javaType="com.atwolf.crud.bean.Department">
        <id column="dept_id" jdbcType="INTEGER" property="deptId" />
        <result column="dept_name" jdbcType="VARCHAR" property="deptName" />
    </association>
  </resultMap>
  <sql id="Base_Column_List">
    emp_id, emp_name, gender, email, d_id
  </sql>
  <sql id="WithDept_Column_List">
    e.emp_id, e.emp_name, e.gender, e.email, e.d_id,d.dept_id,d.dept_name
  </sql>
    <!--查询用户名,用于限制用户名的唯一性  -->
  <select id="selectByCountEmployee" resultMap="WithDept" parameterType="com.atwolf.crud.bean.Employee">
    select
    <include refid="WithDept_Column_List"/>
    from tbl_emp e left join tbl_dept d on d.dept_id=e.d_id
    where e.emp_name=#{empName,jdbcType=VARCHAR}
  </select>  
  <!--多表查询使用:查询员工表的同时,也把部门信息查询出来 -->
  <!-- (单个查询)  public Employee selectByPrimaryKeywithDept(Integer empId);--> 
  <select id="selectByPrimaryKeywithDept" parameterType="java.lang.Integer" resultMap="WithDept">
    select <include refid="WithDept_Column_List" />
    from tbl_emp e left join tbl_dept d
    on d.dept_id=e.d_id
    where emp_id=#{empId,jdbcType=INTEGER}
  </select>
  <!--多表查询使用:查询员工表的同时,也把部门信息查询出来 -->
  <!-- (查询所有) public List<Employee> selectByEmpWithDept(); -->
  <select id="selectByEmpWithDept" resultMap="WithDept">
    select
    <include refid="WithDept_Column_List"/>
    from tbl_emp e left join tbl_dept d on d.dept_id=e.d_id
  </select>
  <!-- 查询所有:public List<Employee> selectByEmployee();  -->
  <select id="selectByEmployee" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List"/>
    from tbl_emp
  </select>
   <!--通过主键ID查询数据  -->
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tbl_emp
    where emp_id = #{empId,jdbcType=INTEGER}
  </select>
  <!--通过主键删除一条记录  -->
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from tbl_emp
    where emp_id = #{empId,jdbcType=INTEGER}
  </delete>
  <!--批量删除  -->
 <delete id="deleteSelectiveEmp" >
    delete from tbl_emp
    where emp_id in
    <foreach item="item" index="index" collection="list" 
        open="(" separator="," close=")">
        #{item}
    </foreach>
  </delete>
  <!--保存全部数据  -->
  <insert id="insert" parameterType="com.atwolf.crud.bean.Employee">
    insert into tbl_emp (emp_id, emp_name, gender, 
      email, d_id)
    values (#{empId,jdbcType=INTEGER}, #{empName,jdbcType=VARCHAR}, #{gender,jdbcType=CHAR}, 
      #{email,jdbcType=VARCHAR}, #{dId,jdbcType=INTEGER})
  </insert>
  <!-- 有选择的保存部分数据 -->
  <insert id="insertSelective" parameterType="com.atwolf.crud.bean.Employee">
    insert into tbl_emp
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="empId != null">
        emp_id,
      </if>
      <if test="empName != null">
        emp_name,
      </if>
      <if test="gender != null">
        gender,
      </if>
      <if test="email != null">
        email,
      </if>
      <if test="dId != null">
        d_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="empId != null">
        #{empId,jdbcType=INTEGER},
      </if>
      <if test="empName != null">
        #{empName,jdbcType=VARCHAR},
      </if>
      <if test="gender != null">
        #{gender,jdbcType=CHAR},
      </if>
      <if test="email != null">
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="dId != null">
        #{dId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <!--有选择的更新字段  -->
  <update id="updateByPrimaryKeySelective" parameterType="com.atwolf.crud.bean.Employee">
    update tbl_emp
    <set>
      <if test="empName != null">
        emp_name = #{empName,jdbcType=VARCHAR},
      </if>
      <if test="gender != null">
        gender = #{gender,jdbcType=CHAR},
      </if>
      <if test="email != null">
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="dId != null">
        d_id = #{dId,jdbcType=INTEGER},
      </if>
    </set>
    where emp_id = #{empId,jdbcType=INTEGER}
  </update>
  <!--更新全部字段  -->
  <update id="updateByPrimaryKey" parameterType="com.atwolf.crud.bean.Employee">
    update tbl_emp
    set emp_name = #{empName,jdbcType=VARCHAR},
      gender = #{gender,jdbcType=CHAR},
      email = #{email,jdbcType=VARCHAR},
      d_id = #{dId,jdbcType=INTEGER}
    where emp_id = #{empId,jdbcType=INTEGER}
  </update>
</mapper>

5.部门service文件

备注:只做了对员工表的查询,新增,修改,删除。因此部门service层内容较少,只做了查询所有,到员工的下拉列表中展示

package com.atwolf.crud.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atwolf.crud.bean.Department;
import com.atwolf.crud.dao.DepartmentMapper;

@Service
public class DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper; 

    //查询所有
    public List<Department> getDepts() {
        List<Department> list=departmentMapper.Depts();
        return list;
    }

}

6.员工service文件

package com.atwolf.crud.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Service;

import com.atwolf.crud.bean.Employee;
import com.atwolf.crud.dao.EmployeeMapper;

@Service
public class EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    //单表查询所有
    public List<Employee> getAll() {
        return employeeMapper.selectByEmployee();
    }

    //一对多查询:查询员工表对应的部门信息
    public List<Employee> getAllEmpWithDept(){
        List<Employee> emplist=employeeMapper.selectByEmpWithDept();
        return emplist;
    }

    /**
     * 保存员工
     * @param employee
     */
    public void saveEmp(Employee employee) {
        employeeMapper.insertSelective(employee);
    }

    /**
     * 服务端校验,用户名是否可用
     * @param empName
     * @return true:代表当前用户名可用,false:不可用
     */
    public boolean checkUser(String empName) {
        Employee emp=new Employee();
        emp.setEmpName(empName);
        List<Employee> list=employeeMapper.selectByCountEmployee(emp);
        int size=list.size();
        System.out.println("size===="+list.size());
        if(size==0){
            return true; //用户名可用
        }else{
            return false;
        }

    }
    /**
     * 按照员工id查询员工
     * @param id
     * @return
     */
    public Employee getEmp(Integer id) {
        Employee employee=employeeMapper.selectByPrimaryKey(id);
        return employee;
    }
    /**
     * 修改:更新按钮的单击事件,保存修改后的信息
     * @param employee
     */
    public void updateEmp(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);   
    }
    /**
     * 删除:根据主键id删除一条记录
     * @param id
     */
    public void deleteEmp(Integer id) {
        employeeMapper.deleteByPrimaryKey(id);
    }
    /**
     * 批量删除
     * @param ids
     */
    public void deleteBatch(List<Integer> ids) {
        employeeMapper.deleteSelectiveEmp(ids);

    }
}

7.部门Controller层

package com.atwolf.crud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.atwolf.crud.bean.Department;
import com.atwolf.crud.service.DepartmentService;
import com.atwolf.crud.utils.Msg;

/**
 * 处理和部门有关的请求
 * @author Administrator
 *
 */

@Controller
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    /**
     * 返回所有部门信息
     */
    @RequestMapping(value="/depts")
    @ResponseBody
    public Msg getDepts(){
        List<Department> list=departmentService.getDepts();
        return Msg.success().add("depts", list);
    }
}

8.员工的Controller层

package com.atwolf.crud.controller;

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

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.atwolf.crud.bean.Employee;
import com.atwolf.crud.service.EmployeeService;
import com.atwolf.crud.utils.Msg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;


    /**
     * 批量删除:也可以单个删(二合一)
     * 批量删除:id的值 1-2-3
     * 单个删除:id的值 1
     */
    @ResponseBody
    @RequestMapping(value="/emp/{ids}",method=RequestMethod.DELETE)
    public Msg deleteEmp(@PathVariable("ids") String ids){
        if(ids.contains("-")){
            List<Integer> del_ids=new ArrayList<Integer>();
            //如果参数ids中包含“-”,就是批量删除
            String[] str_ids = ids.split("-");
            //组装id的集合
            for (String str : str_ids) {
                Integer strids=Integer.parseInt(str);
                del_ids.add(strids);
            }
            employeeService.deleteBatch(del_ids);
        }else{
            Integer id= Integer.parseInt(ids);
            employeeService.deleteEmp(id);
        }
        return Msg.success();
    }
    /**
     * 删除:根据主键id删除一条记录
     * @param id
     * @return
     */
/*  @ResponseBody
    @RequestMapping(value="/emp/{id}",method=RequestMethod.DELETE)
    public Msg deleteEmpById(@PathVariable("id") Integer id){
        employeeService.deleteEmp(id);
        return Msg.success();
    }*/

    /**
     * 修改:更新按钮的单击事件,保存修改后的数据
     */
    @ResponseBody
    @RequestMapping(value="/emp/{empId}",method=RequestMethod.PUT)
    public Msg saveEmp(Employee employee){
        employeeService.updateEmp(employee);
        return Msg.success();
    }

    /**
     * 修改:根据id查询所有员工数据
     * @PathVariable("id")Integer id :@PathVariable("id")是指定参数 Integer id来源于上面路径中的id
     */
    @RequestMapping(value="/emp/{id}",method=RequestMethod.GET)
    @ResponseBody
    public Msg getEmp(@PathVariable("id")Integer id){
        Employee employee=employeeService.getEmp(id);
        return Msg.success().add("emp", employee);
    }



    /**
     * 后端校验:检查用户名是否可用,用户名的唯一性
     * @param empName
     * @return
     */
    @RequestMapping("/checkuser")
    @ResponseBody
    public Msg checkuse(@RequestParam("empName")String empName){
        //前后端保持校验信息一致
        String regx="(^[a-zA-Z0-9_-]{6,16}$)|(^[\u2E80-\u9FFF]{2,5})";
        boolean ide=empName.matches(regx);
        if(!ide){
            return Msg.fail().add("va_msg", "用户名必须是6-16位英文和数字的组合或者2-5位中文");
        }
        //数据库用户名重复校验
        boolean iden=employeeService.checkUser(empName);
        if(iden==true){
            return Msg.success();//用户名可用
        }else{
            return Msg.fail().add("va_msg", "该用户名不可以使用");
        }
    }


    /**
     * 员工保存
     * 1.支持JSR303校验
     * 2.导入Hibernate-Validator包
     * @Valid Employee employee 对封装的数据进行校验
     * BindingResult result 封装校验结果
     * @return
     */
    @RequestMapping(value="/emp",method=RequestMethod.POST)
    @ResponseBody
    public Msg saveEmp(@Valid Employee employee,BindingResult result){
        if(result.hasErrors()){
            Map<String,Object> map =new HashMap<String, Object>();
            //校验失败,应该返回失败,并在模态框中显示校验失败信息
            List<FieldError> errors=result.getFieldErrors();
            for (FieldError fieidError:errors) {
                System.out.println("错误的字段名:"+fieidError.getField());
                System.out.println("错误信息"+fieidError.getDefaultMessage());
                map.put(fieidError.getField(), fieidError.getDefaultMessage());
            }
            return Msg.fail().add("errorFields", map);//传到浏览器显示
        }else{
            employeeService.saveEmp(employee);
            return Msg.success();
        }

    }
    /**
     * 单表分页查询所有
     * @param pn
     * @param model
     * @return
     */
    @RequestMapping("/emps")
    public String getEmps(@RequestParam(value="pn",defaultValue="1")Integer pn,Model model){
        //引入PageHelper分页插件
        //在查询之前只需要调用,参数1:页码,参数2:每页有多少条数据
        PageHelper.startPage(pn, 10);
        //startPage后面紧跟的查询就是一个分页查询
        List<Employee> emps= employeeService.getAll();
        //使用pageInfo包装查询后的结果,只需要将PageInfo交给页面就可以了
        //PageInfo封装了分页的信息,包括查询出来的数据,传入连续显示的页数
        PageInfo page=new PageInfo(emps,5);
        model.addAttribute("pageInfo", page);
        return "list";
    }

    /**
     * 一对多分页查询所有
     */
    @RequestMapping("/empwithdept")
    public String getAllEmpWithDept(@RequestParam(value="pn",defaultValue="1") Integer pn,Model model){
        PageHelper.startPage(pn, 10);
        List<Employee> emps=employeeService.getAllEmpWithDept();
        PageInfo page=new PageInfo(emps,5);
        model.addAttribute("pageInfo", page);
        return "list";
    }
    /**
     *一对多分页查询所有 ,使用AJAX请求
     *@ResponseBody自动将返回的对象转换成json字符串,@ResponseBody要能正常使用,需要导入jackson包
     */
    @RequestMapping("/empwithdeptjson")
    @ResponseBody
    public Msg getEmpsWithJsion(@RequestParam(value="pn",defaultValue="1") Integer pn){
        PageHelper.startPage(pn, 10);
        List<Employee> emps=employeeService.getAllEmpWithDept();
        PageInfo page=new PageInfo(emps,5);
        //直接返回一个对象,该对象会自动转换成json串
        //return page;//写一个通用的处理返回的方法
        return Msg.success().add("pageInfo", page);
    }


}

9.通用的处理后端AJAX返回json信息的类

package com.atwolf.crud.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回json数据的通用返回类
 * @author Administrator
 *
 */

public class Msg {

    //状态码 100-成功 200-失败
    private int code;

    //提示信息
    private String msg;

    //用户要返回给浏览器的数据
    private Map<String,Object> extend =new HashMap<String,Object>();

    public static Msg success(){
        Msg result=new Msg();
        result.setCode(100);
        result.setMsg("处理成功");
        return result;
    }

    public static Msg fail(){
        Msg result=new Msg();
        result.setCode(200);
        result.setMsg("处理失败");
        return result;
    }

    public Msg add(String key,Object value){
        Map<String, Object> map=this.getExtend();
        map.put(key, value);
        return this;
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }



}

10.部门的bean层

package com.atwolf.crud.bean;

public class Department {
    private Integer deptId;

    private String deptName;



    public Department(Integer deptId, String deptName) {
        super();
        this.deptId = deptId;
        this.deptName = deptName;
    }

    public Department() {
        super();
        // TODO Auto-generated constructor stub
    }

    public Integer getDeptId() {
        return deptId;
    }

    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName == null ? null : deptName.trim();
    }
}

11.员工的bean层–包含了后端JSR303校验

package com.atwolf.crud.bean;

import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.Email;

public class Employee {
    private Integer empId;

    @Pattern(regexp="(^[a-zA-Z0-9_-]{6,16}$)|(^[\u2E80-\u9FFF]{2,5})",
            message="用户名必须是2-5位中文或者6-16位英文和数字的组合")
    private String empName;

    private String gender;
    //@Email 主要要使用转义字符/
    @Pattern(regexp="^[a-z\\d]+(\\.[a-z\\d]+)*@([\\da-z](-[\\da-z])?)+(\\.{1,2}[a-z]+)+$",
            message="邮箱格式不正确")
    private String email;

    private Integer dId;
    //一对多查询中,员工表中添加部门信息
    private Department department;



    public Employee(Integer empId, String empName, String gender, String email, Integer dId) {
        super();
        this.empId = empId;
        this.empName = empName;
        this.gender = gender;
        this.email = email;
        this.dId = dId;
    }

    public Employee() {
        super();
        // TODO Auto-generated constructor stub
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public Integer getEmpId() {
        return empId;
    }

    public void setEmpId(Integer empId) {
        this.empId = empId;
    }

    public String getEmpName() {
        return empName;
    }

    public void setEmpName(String empName) {
        this.empName = empName == null ? null : empName.trim();
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender == null ? null : gender.trim();
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }

    public Integer getdId() {
        return dId;
    }

    public void setdId(Integer dId) {
        this.dId = dId;
    }
}

前端的jsp文件见下一篇博客

Bootstrop+jquery+Ajax操作数据

附页码截图

这里写图片描述

这里写图片描述
这里写图片描述

附源码下载网址:
基于Maven依赖的SSM AJAX增删改查demo

  • 7
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值