0
点赞
收藏
分享

微信扫一扫

基于javaweb+jsp的敬老院养老院管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap)

做个橙梦 2022-04-14 阅读 27
javamysql

基于javaweb+jsp的敬老院养老院管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap)

JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap

基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可

开发工具:eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

    private Color getRandomColor(int minColor, int maxColor) {
        Random random = new Random();
        // 保存minColor最大不会超过255
        if (minColor > 255)
            minColor = 255;
        //  保存minColor最大不会超过255
        if (maxColor > 255)
            maxColor = 255;
        //  获得红色的随机颜色值
        int red = minColor + random.nextInt(maxColor - minColor);
        //  获得绿色的随机颜色值
        int green = minColor + random.nextInt(maxColor - minColor);
        //  获得蓝色的随机颜色值
        int blue = minColor + random.nextInt(maxColor - minColor);
        return new Color(red, green, blue);
    }
}
package com.demo.controller;

import com.demo.util.Util;
import com.demo.service.FangjianService;
import com.demo.vo.Fangjian;
        vo.setFangjianName(Util.decode(request, "fangjianName"));
        vo.setFangjianText(Util.decode(request, "fangjianText"));
        fangjianService.update(vo);
        this.redirectList(request, response);
    }

    /**
     * 获取房间的详细信息(详情页面与编辑页面要显示该房间的详情)并跳转回页面
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping({"fangjianGet", "fangjianEditPre"})
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = Util.decode(request, "id");//取出主键id
        Fangjian vo = fangjianService.get(id);
        request.getSession().setAttribute("vo", vo);
        String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
        response.sendRedirect("fangjian_" + to + ".jsp");
    }

    /**
     * 根据条件查询房间的列表并跳转回页面
    <!--修改-->
    <update id="doUpdate" parameterType="com.demo.vo.User">
        UPDATE `t_user`
        <set>
                <if test ='id != null'>`id` = #{id},</if>
                <if test ='username != null'>`username` = #{username},</if>
                <if test ='password != null'>`password` = #{password},</if>
                <if test ='realName != null'>`real_name` = #{realName},</if>
                <if test ='userSex != null'>`user_sex` = #{userSex},</if>
                <if test ='userPhone != null'>`user_phone` = #{userPhone},</if>
                <if test ='userText != null'>`user_text` = #{userText},</if>
                <if test ='userType != null'>`user_type` = #{userType}</if>
        </set>
        WHERE `id` = #{id}
    </update>

    <!--获取-->
        User loginUser = (User) request.getSession().getAttribute("loginUser");
        String oldPassword = Util.decode(request, "oldPassword");
        if (!loginUser.getPassword().equals(oldPassword)) {
            msg = "原密码错误!";
        } else {
            String newPassword = Util.decode(request, "newPassword");
            loginUser.setPassword(newPassword);
            this.userService.update(loginUser);
            msg = "修改成功!";
        }
        request.getSession().setAttribute("alert_msg", msg);
        request.getRequestDispatcher("reset_password.jsp").forward(request, response);
    }

    // 返回一个随机颜色(Color对象)
    private Color getRandomColor(int minColor, int maxColor) {
        Random random = new Random();
        // 保存minColor最大不会超过255
        if (minColor > 255)
            minColor = 255;
        //  保存minColor最大不会超过255
        if (maxColor > 255)
            maxColor = 255;
        //  获得红色的随机颜色值
        //调用Service层的增加(insert)方法
        xinxiService.insert(vo);
        this.redirectList(request, response);
    }

    /**
     * 删除信息
     *
     * @param response
     * @param request
     * @throws IOException
     */
    @RequestMapping("xinxiDelete")
    public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
        Serializable id = Util.decode(request, "id");
        xinxiService.delete(Arrays.asList(id));
        this.redirectList(request, response);
    }
    public void validationCode(HttpServletResponse response, HttpServletRequest request) throws IOException {
        String codeChars = "0123456789";// 图形验证码的字符集合,系统将随机从这个字符串中选择一些字符作为验证码
        //  获得验证码集合的长度
        int charsLength = codeChars.length();
        //  下面三条记录是关闭客户端浏览器的缓冲区
        //  这三条语句都可以关闭浏览器的缓冲区,但是由于浏览器的版本不同,对这三条语句的支持也不同
        //  因此,为了保险起见,建议同时使用这三条语句来关闭浏览器的缓冲区
        response.setHeader("ragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        //  设置图形验证码的长和宽(图形的大小)
        int width = 90, height = 20;
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();//  获得用于输出文字的Graphics对象
        Random random = new Random();
        g.setColor(getRandomColor(180, 250));// 随机设置要填充的颜色
        g.fillRect(0, 0, width, height);//  填充图形背景
        //  设置初始字体
        g.setFont(new Font("Times New Roman", Font.ITALIC, height));
        g.setColor(getRandomColor(120, 180));// 随机设置字体颜色
        //  用于保存最后随机生成的验证码
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 增加公告
     *
     * @param response
     * @param request
    </sql>

    <!--新增-->
    <insert id="doCreate" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.demo.vo.Fangjian">
        INSERT INTO `t_fangjian`
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test ='id != null'>`id`,</if>
                    <if test ='fangjianLouhao != null'>`fangjian_louhao`,</if>
                    <if test ='fangjianFangjianhao != null'>`fangjian_fangjianhao`,</if>
                    <if test ='fangjianLeixin != null'>`fangjian_leixin`,</if>
                    <if test ='fangjianPrice != null'>`fangjian_price`,</if>
                    <if test ='fangjianName != null'>`fangjian_name`,</if>
                    <if test ='fangjianText != null'>`fangjian_text`</if>
        </trim>
    }

    public void setXinxiText(String xinxiText) {
        this.xinxiText = xinxiText;
    }
}
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>用户编辑</title>
    <%@ include file="include/head.jsp" %>
</head>
<body>
<div class="container-fluid">
    <ul class="nav nav-tabs">
        <li><a href="userList">用户列表</a></li>
        <li class="active"><a href="#">编辑</a></li>
    </ul>
    <br/>
    <form class="form-horizontal" role="form" action="userEdit" method="post" onsubmit="return check()">
        <input type="hidden" class="form-control" id="id" name="id" value="${vo.id}"/>
        
            <div class="form-group">
                <label class="col-sm-3 control-label">用户名:</label>
                <div class="col-sm-5">
        DELETE FROM `t_churuyuan` WHERE `id` IN
        <foreach collection="list" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </delete>

    <!--修改-->
    <update id="doUpdate" parameterType="com.demo.vo.Churuyuan">
        UPDATE `t_churuyuan`
        <set>
                <if test ='id != null'>`id` = #{id},</if>
                <if test ='churuyuanName != null'>`churuyuan_name` = #{churuyuanName},</if>
                <if test ='churuyuanJingrushijian != null'>`churuyuan_jingrushijian` = #{churuyuanJingrushijian},</if>
                <if test ='churuyuanLikaishijian != null'>`churuyuan_likaishijian` = #{churuyuanLikaishijian},</if>
                <if test ='churuyuanZhuangtai != null'>`churuyuan_zhuangtai` = #{churuyuanZhuangtai},</if>
                <if test ='churuyuanText != null'>`churuyuan_text` = #{churuyuanText}</if>
        </set>
        WHERE `id` = #{id}
    </update>

    <!--获取-->
    <select id="findById" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" /> FROM `t_churuyuan` WHERE `id` = #{id}
<script type="text/javascript">
    //提交之前进行检查,如果return false,则不允许提交
    function check() {
        //根据ID获取值
        if (document.getElementById("xinxiName").value.trim().length == 0) {
            alert("名字不能为空!");
            return false;
        }
        if (document.getElementById("xinxiIdno").value.trim().length == 0) {
            alert("身份证号不能为空!");
            return false;
        }
        if (document.getElementById("xinxiTel").value.trim().length == 0) {
            alert("手机号不能为空!");
            return false;
        }
        if (document.getElementById("xinxiBir").value.trim().length == 0) {
            alert("出生日期不能为空!");
            return false;
        }
        if (document.getElementById("xinxiZhuzhi").value.trim().length == 0) {
    <!--批量删除-->
    <delete id="doRemoveBatch" parameterType="java.util.Collection">
        DELETE FROM `t_xinxi` WHERE `id` IN
        <foreach collection="list" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </delete>

    <!--修改-->
    <update id="doUpdate" parameterType="com.demo.vo.Xinxi">
        UPDATE `t_xinxi`
        <set>
                <if test ='id != null'>`id` = #{id},</if>
                <if test ='xinxiName != null'>`xinxi_name` = #{xinxiName},</if>
                <if test ='xinxiSex != null'>`xinxi_sex` = #{xinxiSex},</if>
                <if test ='xinxiIdno != null'>`xinxi_idno` = #{xinxiIdno},</if>
                <if test ='xinxiTel != null'>`xinxi_tel` = #{xinxiTel},</if>
                <if test ='xinxiBir != null'>`xinxi_bir` = #{xinxiBir},</if>
                <if test ='xinxiZhuzhi != null'>`xinxi_zhuzhi` = #{xinxiZhuzhi},</if>
                <if test ='xinxiText != null'>`xinxi_text` = #{xinxiText}</if>
        </set>
        WHERE `id` = #{id}
            request.getRequestDispatcher("login.jsp").forward(request, response);
            return;
        }

        Map<String, Object> params = new HashMap();
        params.put("searchColumn", "username");//使用`username`字段进行模糊查询
        params.put("keyword", username);
        List<User> list = (List<User>) userService.list(params).get("list");
        for (User user : list) {
            if (user.getUsername().equals(username) && user.getPassword().equals(password)) {//找到这个管理员了
                request.getSession().setAttribute("loginUser", user);
                request.getRequestDispatcher("menu.jsp").forward(request, response);
                return;
            }
        }
        request.getSession().setAttribute("alert_msg", "错误:用户名或密码错误!");
        request.getRequestDispatcher("login.jsp").forward(request, response);
    }

    @RequestMapping("authRegister")
    public void register(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        String username = Util.decode(request, "username");
        String password = Util.decode(request, "password");
        System.out.println("username=" + username);
        System.out.println("password=" + password);
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test ='id != null'>#{id},</if>
                    <if test ='noticeName != null'>#{noticeName},</if>
                    <if test ='noticeText != null'>#{noticeText},</if>
                    <if test ='noticeType != null'>#{noticeType},</if>
                    <if test ='createDate != null'>#{createDate}</if>
        </trim>
    </insert>

    <!--批量删除-->
    <delete id="doRemoveBatch" parameterType="java.util.Collection">
        DELETE FROM `t_notice` WHERE `id` IN
        <foreach collection="list" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </delete>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test ='id != null'>#{id},</if>
                    <if test ='fangjianLouhao != null'>#{fangjianLouhao},</if>
                    <if test ='fangjianFangjianhao != null'>#{fangjianFangjianhao},</if>
                    <if test ='fangjianLeixin != null'>#{fangjianLeixin},</if>
                    <if test ='fangjianPrice != null'>#{fangjianPrice},</if>
                    <if test ='fangjianName != null'>#{fangjianName},</if>
                    <if test ='fangjianText != null'>#{fangjianText}</if>
        </trim>
    </insert>

    <!--批量删除-->
    <delete id="doRemoveBatch" parameterType="java.util.Collection">
        DELETE FROM `t_fangjian` WHERE `id` IN
        <foreach collection="list" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </delete>

    <!--修改-->
    <update id="doUpdate" parameterType="com.demo.vo.Fangjian">
        UPDATE `t_fangjian`
        <set>
                <if test ='id != null'>`id` = #{id},</if>
                <if test ='fangjianLouhao != null'>`fangjian_louhao` = #{fangjianLouhao},</if>
                <if test ='fangjianFangjianhao != null'>`fangjian_fangjianhao` = #{fangjianFangjianhao},</if>

运行环境

Java≥6、Tomcat≥7.0、MySQL≥5.5

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

技术框架

JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap

基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

登录、注册、退出、用户模块、公告模块、出入院模块、房间模块、信息模块的增删改查管理

20220319000916

20220319000917

20220319000918

20220319000919

20220319000920

20220319000921

20220319000922

20220319000923

20220319000924

document

举报

相关推荐

0 条评论