基于SSM框架和easyUI框架的简易人事管理系统(三)

编程入门 行业动态 更新时间:2024-10-28 17:13:46

基于SSM<a href=https://www.elefans.com/category/jswz/34/1770644.html style=框架和easyUI框架的简易人事管理系统(三)"/>

基于SSM框架和easyUI框架的简易人事管理系统(三)

基于SSM框架和easyUI框架的简易人事管理系统(三)

进行Mapper的编写

本项目是SSM框架,所以连接数据库用的是mybatis。

AdminMapper

xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis//DTD Mapper 3.0//EN"".dtd">
<mapper namespace="dao.AdminDao"><!-- 自定义结果集 --><resultMap type="Admin" id="AdminResult"><id property="id" column="admin_id"/><result property="username" column="username"/><result property="password" column="password"/><result property="role_name" column="role_name"/></resultMap><!-- 登录 --><select id="login" parameterType="Admin" resultMap="AdminResult">select *from admin_tbwhere username = #{username}and password = #{password}</select><!-- 根据条件查询管理员 --><select id="findAdmins" parameterType="Map" resultMap="AdminResult">select * from admin_tb<where><if test="username!=null and username!='' ">username like #{username}</if></where></select><!-- 根据条件查询管理员的人数 --><select id="getCount" parameterType="Map" resultType="Integer">select count(*) from admin_tb<where><if test="username!=null and username!='' ">username like #{username}</if></where></select><!-- 添加管理员 --><insert id="addAdmin" useGeneratedKeys="true" keyProperty="admin_id">insert into admin_tb (username, password)values (#{username}, #{password})</insert><!-- 修改管理员 --><update id="updateAdmin" parameterType="Admin">update admin_tbset username = #{username},password = #{password}where admin_id = #{id}</update><!-- 删除管理员 --><delete id="deleteAdmin" parameterType="Integer">deletefrom admin_tbwhere admin_id = #{id}</delete>
</mapper>

dao

package dao;import domain.Admin;
import org.springframework.stereotype.Repository;import java.util.List;
import java.util.Map;@Repository
public interface AdminDao {/** 登录** @param admin* @return*/public Admin login(Admin admin);/** 根据条件查询管理员** @param map* @return*/public List<Admin> findAdmins(Map<String, Object> map);/** 根据条件查询管理员人数** @param map* @return*/public Integer getCount(Map<String, Object> map);/** 添加管理员** @param admin* @return*/public Integer addAdmin(Admin admin);/** 修改管理员** @param admin* @return*/public Integer updateAdmin(Admin admin);/** 删除管理员** @param id* @return*/public Integer deleteAdmin(Integer id);
}

DepartmentMapper

xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis//DTD Mapper 3.0//EN"".dtd">
<mapper namespace="dao.DepartmentDao"><!-- 自定义结果集 --><resultMap type="Department" id="DepartmentResult"><id property="id" column="dept_id"/><result property="name" column="dept_name"/><result property="description" column="dept_description"/></resultMap><!-- 根据条件查询部门 --><select id="findDepartments" parameterType="Map" resultMap="DepartmentResult">select * from dept_tb<where><if test="name!=null and name!='' ">dept_name like #{name}</if></where></select><!-- 根据条件查询部门数量 --><select id="getCount" parameterType="Map" resultType="Integer">select count(*) from dept_tb<where><if test="name!=null and name!='' ">dept_name like #{name}</if></where></select><!-- 添加部门 --><insert id="addDepartment" useGeneratedKeys="true" keyProperty="dept_id">insert into dept_tb (dept_name, dept_description)values (#{name}, #{description})</insert><!-- 修改部门 --><update id="updateDepartment" parameterType="Department">update dept_tbset dept_name        = #{name},dept_description = #{description}where dept_id = #{id}</update><!-- 删除部门 --><delete id="deleteDepartment" parameterType="Integer">deletefrom dept_tbwhere dept_id = #{id}</delete>
</mapper>

dao

package dao;import domain.Department;
import org.springframework.stereotype.Repository;import java.util.List;
import java.util.Map;@Repository
public interface DepartmentDao {/*** 根据条件查询部门** @param map* @return*/public List<Department> findDepartments(Map<String, Object> map);/*** 根据条件查询部门数量** @param map* @return*/public Integer getCount(Map<String, Object> map);/*** 添加部门** @param department* @return*/public Integer addDepartment(Department department);/*** 修改部门** @param department* @return*/public Integer updateDepartment(Department department);/*** 删除部门** @param id* @return*/public Integer deleteDepartment(Integer id);}

EmployeeMapper

xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis//DTD Mapper 3.0//EN"".dtd">
<mapper namespace="dao.EmployeeDao"><!-- 自定义结果集 --><resultMap type="Employee" id="EmployeeResult"><id property="id" column="emp_id" /><result property="name" column="emp_name" /><result property="sex" column="sex" /><result property="phone" column="phone" /><result property="email" column="email" /><result property="address" column="address" /><result property="education" column="education" /><result property="birthday" column="birthday" /><!-- 关联映射:association --><association property="department" javaType="Department"><id property="id" column="dept_id" /><result property="name" column="dept_name" /></association><association property="position" javaType="Position"><id property="id" column="pos_id" /><result property="name" column="pos_name" /></association></resultMap><!-- 根据条件查询员工 --><select id="findEmployees" parameterType="Map" resultMap="EmployeeResult">select e.emp_id,e.emp_name,e.sex,e.phone,e.email,e.address,e.education,e.birthday,d.dept_id,d.dept_name,p.pos_id,p.pos_namefrom employee_tb e,dept_tb d,position_tb p where e.dept_id = d.dept_idand e.pos_id = p.pos_id<if test="id!=null and id!='' ">and e.emp_id like #{id}</if><if test="name!=null and name!='' ">and e.emp_name like #{name}</if><if test="department_name!=null and department_name!='' ">and d.dept_name like #{department_name}</if><if test="position_name!=null and position_name!='' ">and p.pos_name like #{position_name}</if><if test="sex!=null and sex!='' ">and e.sex like #{sex}</if></select><!-- 根据条件查询员工人数 --><select id="getCount" parameterType="Map" resultType="Integer">select count(*) from employee_tb e,dept_tb d,position_tb p wheree.dept_id = d.dept_idand e.pos_id = p.pos_id<if test="id!=null and id!='' ">and e.emp_id like #{id}</if><if test="name!=null and name!='' ">and e.emp_name like #{name}</if><if test="sex!=null and sex!='' ">and e.sex like #{sex}</if></select><!-- 添加员工 --><insert id="addEmployee" parameterType="Employee">insertinto employee_tb(emp_id,emp_name,sex,phone,email,address,education,birthday,dept_id,pos_id)values(#{id},#{name},#{sex},#{phone},#{email},#{address},#{education},#{birthday},#{department.id},#{position.id})</insert><!-- 修改员工 --><update id="updateEmployee" parameterType="Employee">update employee_tb setemp_name=#{name},sex=#{sex},phone=#{phone},email=#{email},address=#{address},education=#{education},birthday=#{birthday},dept_id=#{department.id},pos_id=#{position.id}where emp_id=#{id}</update><!-- 删除员工 --><delete id="deleteEmployee" parameterType="String">delete from employee_tbwhereemp_id=#{id}</delete></mapper>

dao

package dao;import domain.Employee;
import domain.Post;
import org.springframework.stereotype.Repository;import java.util.List;
import java.util.Map;@Repository
public interface EmployeeDao {/** 根据条件查询员工** @param map* @return*/public List<Post>findEmployees(Map<String, Object> map);/** 根据条件查询员工数量** @param map* @return*/public Integer getCount(Map<String, Object> map);/** 添加员工** @param employee* @return*/public Integer addEmployee(Employee employee);/** 修改员工** @param employee* @return*/public Integer updateEmployee(Employee employee);/** 删除员工** @param id* @return*/public Integer deleteEmployee(String id);
}

Position

xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis//DTD Mapper 3.0//EN"".dtd">
<mapper namespace="dao.PositionDao"><!-- 自定义结果集 --><resultMap type="Position" id="PositionResult"><id property="id" column="pos_id" /><result property="name" column="pos_name" /><result property="description" column="pos_description" /></resultMap><!-- 根据条件查询职位 --><select id="findPositions" parameterType="Map" resultMap="PositionResult">select * from position_tb<where><if test="name!=null and name!='' ">pos_name like #{name}</if></where></select><!-- 根据条件查询职位数量 --><select id="getCount" parameterType="Map" resultType="Integer">select count(*) from position_tb<where><if test="name!=null and name!='' ">pos_name like #{name}</if></where></select><!-- 添加职位 --><insert id="addPosition" useGeneratedKeys="true" keyProperty="pos_id">insert into position_tb(pos_name,pos_description)values(#{name},#{description})</insert><!-- 修改职位 --><update id="updatePosition" parameterType="Position">update position_tb setpos_name=#{name},pos_description=#{description} where pos_id=#{id}</update><!-- 删除职位 --><delete id="deletePosition" parameterType="Integer">delete from position_tb wherepos_id=#{id}</delete>
</mapper>

dao

package dao;import domain.Position;
import org.springframework.stereotype.Repository;import java.util.List;
import java.util.Map;@Repository
public interface PositionDao {/** 根据条件查询职位** @param map* @return*/public List<Position> findPositions(Map<String, Object> map);/** 根据条件查询职位数量** @param map* @return*/public Integer getCount(Map<String, Object> map);/** 添加职位** @param position* @return*/public Integer addPosition(Position position);/** 修改职位** @param position* @return*/public Integer updatePosition(Position position);/** 删除职位** @param id* @return*/public Integer deletePosition(Integer id);
}

Post

xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis//DTD Mapper 3.0//EN"".dtd">
<mapper namespace="dao.PostDao"><!-- 自定义结果集 --><resultMap type="Post" id="PostResult"><id property="id" column="post_id" /><result property="title" column="title" /><result property="content" column="content" /><result property="date" column="create_date" /><association property="admin" javaType="Admin"><id property="id" column="admin_id" /><result property="username" column="username" /></association></resultMap><!-- 根据条件查询公告 --><select id="findPosts" parameterType="Map" resultMap="PostResult">select a.admin_id,a.username,p.post_id,p.title,p.content,p.create_datefrom admin_tb a,post_tb p where p.admin_id = a.admin_id<if test="title!=null and title!='' ">and p.title like #{title}</if></select><!-- 根据条件查询公告数量 --><select id="getCount" parameterType="Map" resultType="Integer">select count(*) from post_tb<where><if test="title!=null and title!='' ">title like #{title}</if></where></select><!-- 添加公告 --><insert id="addPost" useGeneratedKeys="true" keyProperty="post_id">insertinto post_tb(title,content,admin_id,create_date)values(#{title},#{content},#{admin.id},#{date})</insert><!-- 修改公告 --><update id="updatePost" parameterType="Post">update post_tb settitle=#{title},content=#{content},admin_id=#{admin.id},create_date=#{date}where post_id=#{id}</update><!-- 删除公告 --><delete id="deletePost" parameterType="Integer">delete from post_tbwherepost_id=#{id}</delete><!-- 根据 ID 查询公告信息 --><select id="getPostById" parameterType="Integer" resultMap="PostResult">select a.admin_id,a.username,p.post_id,p.title,p.content,p.create_datefrom admin_tb a,post_tb p where p.admin_id = a.admin_id andp.post_id=#{id}</select>
</mapper>

dao

package dao;import domain.Post;
import org.springframework.stereotype.Repository;import java.util.List;
import java.util.Map;@Repository
public interface PostDao {/** 根据条件查询公告** @return*/public List<Post>findPosts(Map<String, Object> map);/** 根据条件查询公告数量** @param map* @return*/public Integer getCount(Map<String, Object> map);/** 添加公告** @param post* @return*/public Integer addPost(Post post);/** 修改公告** @param post* @return*/public Integer updatePost(Post post);/** 删除公告** @param id* @return*/public Integer deletePost(Integer id);/** 根据 ID 查询公告信息** @param id* @return*/public Post getPostById(Integer id);
}

mybatis 配置文件

mybatis1-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis//DTD Config 3.0//EN"".dtd">
<configuration><!-- 为JavaBean 起类别名 --><typeAliases><package name="domain" /></typeAliases>
</configuration>

jdbc

大家基本都会这边就不展示了,我用的是oracle的数据库所以jdbc也是oracle,大家可以按照自己喜好去码

更多推荐

基于SSM框架和easyUI框架的简易人事管理系统(三)

本文发布于:2024-03-09 13:03:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1725031.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框架   简易   人事管理系统   SSM   easyUI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!