栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SSM实战项目:人事管理系统(蓝色版)【附源代码】

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SSM实战项目:人事管理系统(蓝色版)【附源代码】

程序员小王的博客:程序员小王的博客
 欢迎点赞  收藏 ⭐留言 
 如有编辑错误联系作者,如果有比较好的文章欢迎分享给我,我会取其精华去其糟粕
java自学的学习路线:java自学的学习路线

一、员工管理系统项目说明:

该项目主要是完成Spring+SpringMVC+mybatis的完整整合,功能实现比较单一,就是一个完成增删改查的小项目!

源代码在githee仓库:SSM实战项目:人事管理系统(蓝色版)

1、整个项目实现功能

管理员的登录,注册,员工的增删改查,批量删除,整个系统设计的目标人群是管理者,系统的主要功能是对员工进行各种信息的操作。主要是完成对数据库的增删改查的功能。

2、开发环境
分类名称语种
操作系统windows10简体中文
数据库平台MySQL Server 8.0+
应用服务器apache-tomcat-8.5.71
java开发工具idea
框架mybatis+Spring+SpringMVC
项目名称《学生教务系统》
实现技术mybatis+Spring+SpringMVC+mysql+Servlet+jquery+bootStrap+js+Maven+tomcat等技术
3、数据库表设计
-- 创建员工表
create table t_emp(
id int primary key auto_increment,
name varchar(20) not null,
salary double not null,
age int not null
)

-- 添加员工数据
insert into t_emp values(null,'王恒杰',20000,21);
insert into t_emp values(null,'杨福君',9000,19);
-- 查询员工数据
select * from t_emp;

-- 创建管理员表
create table t_admin(
  id    int  primary key auto_increment,
 username varchar(20),
 password varchar(50)
)
-- 添加数据
insert into t_admin values(null,'王恒杰','123456');
-- 查询
select * from t_admin
4、Maven导入项目所依赖的jar包
  
        
            junit
            junit
            4.11
            test
        
        
            org.springframework
            spring-core
            4.3.2.RELEASE
        
        
            org.springframework
            spring-context
            4.3.2.RELEASE
        
        
            org.springframework
            spring-context-support
            4.3.2.RELEASE
        
        
            org.springframework
            spring-jdbc
            4.3.2.RELEASE
        
        
            org.springframework
            spring-aop
            4.3.2.RELEASE
        
        
            org.springframework
            spring-beans
            4.3.2.RELEASE
        
        
            org.springframework
            spring-expression
            4.3.2.RELEASE
        
        
            org.springframework
            spring-aspects
            4.3.2.RELEASE
        
        
            org.springframework
            spring-tx
            4.3.2.RELEASE
        
        
            org.springframework
            spring-web
            4.3.2.RELEASE
        
        
        
            org.springframework
            spring-webmvc
            4.3.2.RELEASE
        
        
        
            javax.servlet
            servlet-api
            2.5
            provided
        

        
        
            javax.servlet.jsp
            jsp-api
            2.1
        
        
        
            jstl
            jstl
            1.2
        
        
        
            mysql
            mysql-connector-java
            8.0.16
        

        
        
            org.mybatis
            mybatis
            3.4.6
        

        
        
            org.mybatis
            mybatis-spring
            1.3.1
        
5、Spring+mybatis整合工厂(applicationContext.xml)
    
    
  
    
    
   
    
    
        
        
        
        
    

    
    
        
        
        
         
3、功能测试(adminTest) 
public class AdminTest {
    @Test
    public void login(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        AdminService adminService = (AdminService) context.getBean("adminService");
        Admin admin = new Admin(null,null, "王恒杰", "123456",true);

        Admin login = adminService.login(admin);
        System.out.println(login);
    }

    @Test
    public void register(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        AdminService adminService = (AdminService) context.getBean("adminService");
        Admin admin = new Admin(null, "风犬少年","邓正武", "234567",true);
        adminService.register(admin);
    }
}
4、Controller层
@Controller("adminController")
@RequestMapping("admin")
public class AdminController {
    
    @Autowired
    private AdminService adminService;

    
    @RequestMapping("login")
    public String login(Admin admin,HttpServletRequest request){
        String password = MD5Utils.md5(admin.getPassword());
        admin.setPassword(password);
        Admin admin1 = adminService.login(admin);
        System.out.println(admin1);
        if(admin1!=null){
            request.getSession().setAttribute("admin",admin1);
            return "redirect:/emp/show";
        }
       return "redirect:/login.jsp";
    }
    
    @RequestMapping("register")
    public String register(Admin admin){
        String password = MD5Utils.md5(admin.getPassword());
        admin.setPassword(password);
        adminService.register(admin);
        return "redirect:/login.jsp";
    }

    
    @RequestMapping("destroy")
    public String destroy(HttpServletRequest request){
        request.getSession().invalidate();
        return "redirect:/login.jsp";
    }

}

三、员工增删改查功能模块的开发
  • 员工的增删改查功能

  • 员工展示页面

  • 添加员工示意图

  • 修改员工示意图

1、dao层(empDao.java)
public interface EmpDao {
    
    public void insert(Emp emp);

    
    public void deleteById(Integer id);

    
    public List showEmp();

    
    public void updateEmp(Emp emp);

    
    public Emp selectEmpById(Integer id);
}
 
2、Service层 
(1)empService接口层 
public interface EmpService {
    
    public void insert(Emp emp);

    
    public void deleteById(Integer id);

    
    public List showEmp();

    
    public void updateEmp(Emp emp);

    
    public Emp selectEmpById(Integer id);
}

(2)empServiceImpl实现类
@Service("empService")

@Transactional
public class EmpServiceImpl implements EmpService {
    
    @Autowired
    private EmpDao empDao;

    public void setEmpDao(EmpDao empDao) {
        this.empDao = empDao;
    }

    @Override
    public void insert(Emp emp) {
        empDao.insert(emp);
    }

    @Override
    public void deleteById(Integer id) {
    empDao.deleteById(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List showEmp() {
        return empDao.showEmp();
    }

    @Override
    public void updateEmp(Emp emp) {
        empDao.updateEmp(emp);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Emp selectEmpById(Integer id) {
        return empDao.selectEmpById(id);
    }
}
 
3、功能测试(EmpTest) 
public class EmpTest {
    
    @Test
    public void insert(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        EmpService empService = (EmpService) context.getBean("empService");
        Emp emp = new Emp(null,"邓正武",2000d,22);
        empService.insert(emp);
    }


    
    @Test
    public void deleteById(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        EmpService empService = (EmpService) context.getBean("empService");
        empService.deleteById(4);
    }


    
    @Test
    public void showEmp(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        EmpService empService = (EmpService) context.getBean("empService");
        List emps = empService.showEmp();
        for (Emp emp : emps) {
            System.out.println(emp);
        }
    }

    
    @Test
    public void updateEmp(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        EmpService empService = (EmpService) context.getBean("empService");
        Emp emp = new Emp(3,"邓正武",38000d,23);
        empService.updateEmp(emp);
    }
    
    @Test
    public void selectEmpById(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        EmpService empService = (EmpService) context.getBean("empService");
        Emp emp = empService.selectEmpById(1);
        System.out.println(emp);
    }
}

4、Controller层
@Controller("emoController")
@RequestMapping("emp")
public class EmpController {
    
    @Autowired
    private EmpService empService;

    
    @RequestMapping("insert")
    public String insert(Emp emp){

        empService.insert(emp);
        return "redirect:/emp/show";
    }


    
    @RequestMapping("delete")
    public String  deleteById(Emp emp){
        empService.deleteById(emp.getId());
  return "redirect:/emp/show";
    }

    
    @RequestMapping("show")
    public String showEmp(Model model){
        //调用业务方法
        List emps = empService.showEmp();
        //作用域
        model.addAttribute("emps",emps);
        return "emplist";
    }

    
    @RequestMapping("update")
    public String  updateEmp(Emp emp){
        empService.updateEmp(emp);
        return "redirect:/emp/show";
    }


    
    @RequestMapping("select")
    public String selectEmpById(Integer id,Model model){
        Emp emp = empService.selectEmpById(id);
        model.addAttribute("emp",emp);
        return "updateEmp";
    }
}

源代码在githee仓库:SSM实战项目:人事管理系统(蓝色版)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/571192.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号