Java项目:火车票预订系统(java+JDBC+JSP+Servlet+html+mysql)

news/2024/5/18 23:11:13 标签: java, mysql, html, servlet, jdbc
htmledit_views">

源码获取:博客首页 "资源" 里下载!

一、项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + html" title=mysql>mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP + Servlert + html+ css + JavaScript + JQuery + Ajax 等等;
 

 

 

 

 

 

 

个人中心Controller:

/**
 * 个人中心Controller
 */
@Controller
public class UserInforController {
	
    @Autowired
    private UserInforServiceImpl userInforService = null;

    /**
     * 修改密码操作
     * @param oldPassword
     * @param newPassword
     * @param rePassword
     * @param httpSession
     * @return
     */
    @RequestMapping("changePassword.do")
    @ResponseBody
    public Map<String, String> changePassword(String oldPassword, String newPassword,
                                              String rePassword, HttpSession httpSession){
        HashMap<String, String> map = new HashMap<String, String>();
        if (newPassword.equals(rePassword)){
            SystemManager admin = (SystemManager) httpSession.getAttribute("admin");
            String encodeByMD5 = MD5Utils.encodeByMD5(oldPassword);
            if (encodeByMD5.equals(admin.getSmPassword())){
                String newPasswords = MD5Utils.encodeByMD5(newPassword);
                admin.setSmPassword(newPasswords);
                userInforService.updateSystemManagePassword(admin.getSmId(),admin);
                map.put("type","success");
                map.put("msg","密码修改成功");
                return map;
            }else{
                map.put("type","error");
                map.put("msg","原密码错误");
                return map;
            }
        }else{
            map.put("type","error");
            map.put("msg","两次密码不一致");
            return map;
        }
    }
    
    /**
     * 员工修改个人密码
     * @param oldPassword
     * @param newPassword
     * @param rePassword
     * @param httpSession
     * @return
     */
    @RequestMapping("changeEmployeePassword.do")
    @ResponseBody
    public Map<String, String> changeEmployeePassword(String oldPassword, String newPassword,
                                              String rePassword, HttpSession httpSession){
        HashMap<String, String> map = new HashMap<String, String>();
        if (newPassword.equals(rePassword)){
            Integer eid = (Integer) httpSession.getAttribute("employeeId");
            try {
                userInforService.updateEmployeePassword(eid, oldPassword, newPassword);
                map.put("type","success");
                map.put("msg","密码修改成功");
                return map;
            } catch (CustomException e) {
                map.put("type","error");
                map.put("msg","原密码错误");
                return map;
            }
        }else{
            map.put("type","error");
            map.put("msg","两次密码不一致");
            return map;
        }
    }

    /**
     * 查看个人信息
     * @param httpSession
     * @return
     */
    @RequestMapping("inforEmployee.do")
    public @ResponseBody EmployeeCustomVo getInforEmployee(HttpSession httpSession){
        Integer id = (Integer) httpSession.getAttribute("employeeId");
        EmployeeCustomVo employeeCustomVo = userInforService.getInforEmployee(id);
        return employeeCustomVo;
    }

    /**
     * 修改个人信息
     * @param httpSession
     * @param employee
     * @return
     */
    @ResponseBody
    @RequestMapping("updateInforEmployee.do")
    public Message updateInforEmployee(HttpSession httpSession, Employee employee){
        Integer id = (Integer) httpSession.getAttribute("employeeId");
        employee.seteId(id);
        if(userInforService.updateEmploueeById(id,employee)<=0) {
        	return Message.error("修改信息失败");
        }
       return Message.success();
    }



    /**
     * 个人工资信息
     * @param pageNum
     * @param limit
     * @param year
     * @param httpSession
     * @return
     * @throws Exception
     */
    @RequestMapping("employeeSalaryList.do")
    @ResponseBody
    public EmployeeSalaryVO findSelective(
            @RequestParam(value="page", defaultValue="1")int pageNum,
            @RequestParam(value="limit", defaultValue="10") int limit,
            @RequestParam(value="year", defaultValue="1") String year,
            HttpSession httpSession) throws Exception {

        Integer eId = (Integer) httpSession.getAttribute("employeeId");
        //pageNum:起始页面  pageSize:每页的大小
        PageHelper.startPage(pageNum,limit);
        //查找条件,一定要紧跟在startPage后
        List<Salary> salaryList = userInforService.getEmployeeSalaryList(eId, year);

        PageInfo pageResult = new PageInfo(salaryList);

        //设置前台需要的数据
        EmployeeSalaryVO employeeSalaryVO = new EmployeeSalaryVO();
        employeeSalaryVO.setCode(0);
        employeeSalaryVO.setMsg("");
        employeeSalaryVO.setCount((int) pageResult.getTotal());
        employeeSalaryVO.setData(pageResult.getList());
        return employeeSalaryVO;
    }

}

管理员和员工登陆控制:

/**
 * @Author: admin
 * @Description: 管理员和员工登陆控制
 **/
@Controller
public class LoginController {
    @Autowired
    private LoginServiceImpl loginService = null;
    /**
     * @Author: admin
     * @Description: 验证码变更
     * @Date: 14:33 2021/10/5
     * @Param: [request, response]
     * @Return: void
     **/
    @RequestMapping(value = "/changeCode.do")
    @ResponseBody
    public void getIdentifyingCode(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        // 验证码存储在session的identifyingCode,属性中
        CaptchaUtil.outputCaptcha(request, response);
    }

    // 获取员工登陆界面
    @RequestMapping("/")
    public String getLoginPage(){
        return "employee/login.html";
    }

    // 获取管理员登陆界面
    @RequestMapping("/admin.do")
    public String getAdminLoginPage(HttpServletRequest request){
    	String realPath = request.getServletContext().getRealPath("/");
    	request.getSession().setAttribute("realPath", realPath);
        return "admin/adminLogin.html";
    }
    
    
    /**
     * 员工登录操作
     * @param model
     * @param httpSession
     * @param username
     * @param password
     * @param identifyingcode
     * @return
     */
    @RequestMapping(value = "/employeeLogin.do")
    @ResponseBody
    public Message employeeLogin(HttpSession httpSession, String username,
                             String password, String identifyingcode)
    {
    	if(StringUtils.isEmpty(username)) {
    		return Message.error("请填写工号");
    	}
    	if(StringUtils.isEmpty(password)) {
    		return Message.error("请填写密码");
    	}
    	if(StringUtils.isEmpty(identifyingcode)) {
    		return Message.error("请填写验证码");
    	}
        String code = (String) httpSession.getAttribute("identifyingCode");
        if(!identifyingcode.equalsIgnoreCase(code)){
        	return Message.error("验证码错误");  
        }
        Employee employee = loginService.findEmployeeByIdAndPassword(username, password);
        if(employee==null) {
        	return Message.error("工号或密码错误");
        	
        } 
        httpSession.setAttribute("employeeId",employee.geteId());
       return Message.success("员工登录成功");
    }

    @RequestMapping(value = "/loginSuccess.do")
    public String loginSucceses(Model model) throws Exception
    {
        return "employee/index.html";
    }

    /**
     * 管理员登录操作
     * @param model
     * @param httpSession
     * @param username
     * @param password
     * @param identifyingcode
     * @return
     */
    @RequestMapping(value = "/adminLogin.do")
    @ResponseBody
    public Message adminLogin(HttpSession httpSession, String username,
                                            String password, String identifyingcode)
    {
        
    	if(StringUtils.isEmpty(username)) {
    		return Message.error("请填写账号");
    	}
    	if(StringUtils.isEmpty(password)) {
    		return Message.error("请填写密码");
    	}
    	if(StringUtils.isEmpty(identifyingcode)) {
    		return Message.error("请填写验证码");
    	}
        String code = (String) httpSession.getAttribute("identifyingCode");
        if(identifyingcode.equalsIgnoreCase(code)){
            SystemManager manager = loginService.findSystemManagerByIdAndPassword(username, password);
           if(manager==null) {
        	   return Message.error("账号或密码错误");
           }
            // 保存到session
            httpSession.setAttribute("admin",manager);
            return Message.success("登录成功");
        }else {
        	return Message.error("验证码错误");
        }
    }
    @RequestMapping(value = "/getAdminAccount.do")
    @ResponseBody
    public String getAdminAccount(HttpSession httpSession){
        SystemManager systemManager = (SystemManager) httpSession.getAttribute("admin");
//        SystemManager manager = loginService.findSystemManagerById(id);
        return systemManager.getSmAccount();
    }

    @RequestMapping(value = "/getEmployeeAccount.do")
    @ResponseBody
    public Map<String,String> getEmployeeAccount(HttpSession httpSession){
        Integer id = (Integer) httpSession.getAttribute("employeeId");
        Employee employee = loginService.findEmployeeById(id);
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("account",employee.geteAccount());
        map.put("name",employee.geteName());
        return map;
    }
    @RequestMapping(value = "/logout.do")
    public String logout(HttpSession httpSession){
        httpSession.removeAttribute("employeeId");
        return "redirect:/";
    }

    @RequestMapping(value = "/logoutAdmin.do")
    public String logoutAdmin(HttpSession httpSession){
       httpSession.removeAttribute("admin");
       return "redirect:/admin.do";
    }
}

用户管理操作: 

/**
 * 用户管理操作
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户添加页面
     * @return
     */
    @GetMapping("/add")
    public String create() {
        return "user/add";
    }

    /**
     * 用户添加操作
     * @param user
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Map<String, Object> add(@RequestBody User user) {
        if(StringUtils.isEmpty(user.getUserName())){
            return MapControl.getInstance().error("请填写用户名").getMap();
        }
        if(StringUtils.isEmpty(user.getName())){
            return MapControl.getInstance().error("请填写名称").getMap();
        }
        if(StringUtils.isEmpty(user.getUserPwd())){
            return MapControl.getInstance().error("请填写密码").getMap();
        }
        int result = userService.create(user);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    @ResponseBody
    public Map<String, Object> delete(@PathVariable("id") Integer id) {
        int result = userService.delete(id);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //批量删除
    @PostMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(String ids) {
        int result = userService.delete(ids);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    /**
     * 编辑用户信息操作
     * @param user
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public Map<String, Object> edit(@RequestBody User user) {
        if(StringUtils.isEmpty(user.getUserName())){
            return MapControl.getInstance().error("请填写用户名").getMap();
        }
        if(StringUtils.isEmpty(user.getName())){
            return MapControl.getInstance().error("请填写名称").getMap();
        }
        if(StringUtils.isEmpty(user.getUserPwd())){
            return MapControl.getInstance().error("请填写密码").getMap();
        }
        int result = userService.update(user);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    /**
     * 根据id查询,跳转修改页面
     * @param id
     * @param modelMap
     * @return
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap modelMap) {
        User user = userService.detail(id);
        modelMap.addAttribute("user", user);
        return "user/edit";
    }

    //查询所有
    @PostMapping("/query")
    @ResponseBody
    public Map<String, Object> query(@RequestBody User user) {
        List<User> list = userService.query(user);
        Integer count = userService.count(user);
        return MapControl.getInstance().success().page(list, count).getMap();
    }

    //跳转列表页面
    @GetMapping("/list")
    public String list() {
        return "user/list";
    }

}

源码获取:博客首页 "资源" 里下载!


http://www.niftyadmin.cn/n/1554253.html

相关文章

.net clr procedure能否与mysql集成_SQL2005新功能:[1]CLR集成

第一项新功能&#xff1a;Microsoft .NET Framework 公共语言运行时集成Microsoft .NET Framework 公共语言运行时 (CLR) 现在寄宿于 SQL Server 数据库引擎中。此 CLR 集成环境支持过程数据库对象&#xff0c;包括用基于 .NET Framework 的语言(如 Microsoft Visual C# 和 Vis…

Java项目:小蜜蜂扩音器网上商城系统(java+JSP+Servlet+JDBC+Ajax+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 用户功能模块&#xff1a; 用户注册&#xff1a; 用户登录&#xff1a;商品模块&#xff1a;订单模块&#xff1b;后台管理系统功能&#xff1a;管理员模块&#xff1a; 商品模块&#xff1a;…

elasticsearch 工具类_搜索接口优化方案——elasticsearch分布式搜索引擎的基本使用...

前言&#xff1a;在开发项目中一般都会有搜索功能。如果是面向C端的搜索功能&#xff0c;往往都特别考验性能。比如普通的商城系统中的商品搜索或者一些资源的站内搜索。可能以前的做法就是对商品表做一个按名称或商品描述做模糊查询。更好一点的是对搜索关键字进行分词&#x…

Java项目:养老院管理系统(java+SSM+JSP+Easyui+maven+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 运行环境&#xff1a; JDK1.8、tomcat8、eclipse、mysql5.6、Navicat 功能实现&#xff1a; 用户: 用户名,登录密码,姓名,性别,出生日期,用户照片,联系电话,邮箱,家庭地址,注册时间 老人: 老人编号,姓名,…

thinkphp mysql 自加_自增 · ThinkPHP5+数据库和模型 · 看云

更新数据表中的数据~~~Db::table(think_user)->where(id, 1)->update([name > thinkphp]);~~~如果数据中包含主键&#xff0c;可以直接使用&#xff1a;~~~Db::table(think_user)->update([name > thinkphp,id>1]);~~~update 方法返回影响数据的条数&#xf…

Java项目:酒店人事管理系统(java+SSM+JSP+JQuery+Ajax+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目运行 环境配置&#xff1a; Jdk1.8 Tomcat8.5 mysql Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09; 项目技术&#xff1a; JSP Spring SpringMVC MyBatis ht…

区块链智能合约与mysql_什么是智能合约? 韭菜们请细看

智能合约又称智能合同&#xff0c;它是由事件驱动的、具有状态的、获得多方承认的、运行在区块链之上的、且能够根据预设条件自动处理资产的程序&#xff0c;智能合约最大的优势是利用程序算法替代人去仲裁和执行合同。简言之&#xff0c;智能合约是一种用计算机语言取代法律语…

Java项目:健身器材商城系统(java+Jdbc+Servlet+Ajax+Fileupload+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目运行 环境配置&#xff1a; Jdk1.8 Tomcat8.5 mysql Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09; 项目技术&#xff1a; Jdbc Servlert html css JavaScrip…