如何使用ssm实现基于web的马病管理系统设计与实现

250 篇文章 0 订阅
146 篇文章 0 订阅

@TOC

ssm536基于web的马病管理系统设计与实现+jsp

第一章 课题背景及研究内容

1.1 课题背景

信息数据从传统到当代,是一直在变革当中,突如其来的互联网让传统的信息管理看到了革命性的曙光,因为传统信息管理从时效性,还是安全性,还是可操作性等各个方面来讲,遇到了互联网时代才发现能补上自古以来的短板,有效的提升管理的效率和业务水平。传统的管理模式,时间越久管理的内容越多,也需要更多的人来对数据进行整理,并且数据的汇总查询方面效率也是极其的低下,并且数据安全方面永远不会保证安全性能。结合数据内容管理的种种缺点,在互联网时代都可以得到有效的补充。结合先进的互联网技术,开发符合需求的软件,让数据内容管理不管是从录入的及时性,查看的及时性还是汇总分析的及时性,都能让正确率达到最高,管理更加的科学和便捷。本次开发的马病管理系统实现了字典管理、论坛管理、用户信息管理、马病管理、马病收藏管理、马病留言管理、用户管理、员工管理、管理员管理等功能。系统用到了关系型数据库中王者MySql作为系统的数据库,有效的对数据进行安全的存储,有效的备份,对数据可靠性方面得到了保证。并且程序也具备程序需求的所有功能,使得操作性还是安全性都大大提高,让马病管理系统更能从理念走到现实,确确实实的让人们提升信息处理效率。

1.2 开发目的和意义

小康时代的到来,使得人们满意度上升,生活各个方面都产生了许多变化,比如办公都有相应软件,很多工作都要求员工会操作计算机,可以说现在的时代基本被软件覆盖得差不多了,软件行业的特征就是大家都在使用软件代替传统手工记载操作,软件的出现让我们的生活还有工作又向前翻了新篇章。马病管理系统是一个利用软件形式管理车辆租赁信息的平台。管理员管理租车信息也不再需要用纸张进行信息记录及查询管理操作,所有的操作都是利用电脑进行办公,用户需要使用密码还有用户名进行系统登录操作,按照系统主页界面的各个功能展示进行相关操作,无论添加或者是删除,拟或是修改查询等操作,时间上不需要太多,短短几分钟就会搞定。况且软件是不限制办公地点以及办公时间的,只要有操作需要,随时随地登录系统就可以完成任务。办公效率提高这个不再是难题。汽车租赁店对于租车信息的管理操作早就应该进行变革了,利用软件管理租车信息,节约人力物力成本,这是一个新的租车信息管理的创举。

1.3 论文研究内容

本次开发的马病管理系统的论文从下面几个部分进行编写:

第一章:本章介绍了程序开发背景和目的意义,罗列出了论文写作内容信息,让我们知道论文编写是如何进展的。

第二章:本章主要讲解了系统开发用到的相关技术方面的知识,比如SSM技术,MySQL数据库知识等内容。帮助人们更好的理解系统技术上面的相关知识。

第三章:文章第3章主要介绍了系统开发的可行性问题,从经济,时间,操作等内容上面进行了大致介绍,确定系统开发确实可行,然后分析了系统的开发流程,确定系统需要具备的大概的功能,保障系统能够稳定使用和运行。

第四章:这个章节主要绘制出了系统功能架构,让我们更直观了解马病管理系统的功能,对后台数据库表进行了设计,还画出了对应的E-R图。

第五章:这个章节主要介绍系统各个部分功能具体实现的界面效果。让我们了解到各个部分的功能详细情况。

第六章:这个部分主要就是对马病管理系统进行整体测试,看看程序是否能够达到用户使用要求,程序能否进行验收上交操作。

第二章 相关技术

本次开发马病管理系统使用的是B/S结构模式进行程序开发,程序开发使用到了SSM技术,马病管理系统的数据信息选择MySQL数据库进行存放。

2.1 B/S结构

B/S结构实际上就是Browser/Server(浏览器/服务器)的缩写,B/S结构是目前软件开发中的主流结构,大多数软件开发者都采用B/S这样的三层体系结构。采用B/S结构开发的马病管理系统能够大大方便用户使用操作,用户随时随地都可以进行马病管理系统的访问操作,只需要用户拥有一台会连上网络的计算机就行了,并且使用B/S 模式开发的马病管理系统是基于浏览器的操作方式,在与用户进行交互以及程序的表现方式上面将会更加吸引人,这样的模式也给程序员开发程序降低了难度,程序开发成本也会相应缩减不少。我们在使用马病管理系统期间,系统也会随着用户需求进行完善升级,使用B/S 模式开发的马病管理系统就完全不需要担心,因为它的升级速度快,升级产生的成本费用很低,大多依赖于用户自己在网络上下载最新版本进行安装完成程序更新。下图为B/S结构图。

图2.2 B/S结构图

2.2 MySQL数据库

马病管理系统后台数据库使用的是MySQL进行数据库方面的开发工作的,MySQL它是微软开发的一款平台软件,这个软件可以给用户提供高效率的智能数据,并且数据信息还是很可靠,使用它进行数据存储可以满足大众企业管理各种各样的数据信息的需求。MySQL在MySQL版本里面它是最全面的,也是最强大的开发平台, MySQL在许多关键之处都进行了改进的操作,它也增加了很多新特性,这些改进和更新让公司能够对关键应用程序进行高效运行,并且还可以让公司降低发送信息给用户的成本,以及降低数据信息管理的基础设施。因此MySQL在公司以及企业中它的地位是非常高的,ERP还有OA系统,以及公司财务的系统都离不开MySQL,在软件开发非常流行的今天,MySQL也被用来作为网站开发的网站后台数据库,可以说公司使用MySQL进行数据管理不仅节约成本,还可以让公司数据信息的管理效率大大提高,公司数据存放在MySQL平台上,数据信息的安全性也不用担心,因为MySQL他可以给数据库里面的日志还有数据文件以及整个数据库进行加密操作,另外MySQL还提供在线备份功能,这样可以节约存储空间,加快数据备份的速度。总之,选择MySQL进行在线系统的后台数据库开发是很有优势的。这是个不错的软件选择。

第三章 系统分析

3.1可行性分析

可行性分析从时间,经济以及操作和技术上面进行调查和研究,确保合理利用信息资源,避免在进行程序设计过程中因为考虑不周到所带来的困扰,帮助我们更好的进行程序设计。

3.1.1时间可行性

本次进行系统开发,我预留了两个月时间来完成,从系统的需求分析,功能结构设计,功能详细设计以及系统测试等环节,两个月时间是可以完成程序开发操作的,我打算每天早中晚都进行程序的编写操作,这期间也包括查阅各种资料信息,加上同学以及老师的帮助和指点,相信程序开发的时间也会缩短不少。所以时间上是可行的。

3.1.2 经济可行性

马病管理系统的开发平台是Myeclipse,数据库选用MySQL数据库,使用的浏览器都是大众浏览器,这些软件是不需要收费就能进行下载安装操作的。在系统开发的硬件选择上面,我使用的是自己的笔记本进行开发操作。因此在进行系统开发时,经济上面无需额外支出。开发出来的程序可以提高办公效率,带来的经济效益比较高,系统开发的投入产出比很可观。

3.1.3 操作可行性

马病管理系统的界面设计比较简单,界面布局根据用户日常使用习惯进行设计,网站各个功能在导航栏里面清晰可见,网站的数据操作可视化,用户操作网站不需要培训就能上手,只需要跟着网站功能提示进行操作就行。

3.1.4 技术可行性

作为计算机专业学生,在学校期间就学习到许多关于编程方面的知识,像SSM技术,还有MySQL数据库等知识,我对Myeclipse开发平台以及MySQL数据库的操作也比较熟练,所以技术上面还是有一定把握。

3.1.5 法律可行性

自己本人开发的软件和用到的资料来源都是图书馆以及百度文库和百度网页等渠道,并不涉及违法。在个人毕业设计上面,无论源代码还是论文编写内容不存在抄袭行为。

从上面的经济,操作以及时间上面进行的分析,得出结论就是这次开发的马病管理系统在开发上面是能够进行的,系统开发出来能创造更大的经济效益,越早开发升值空间越大。

3.2系统流程分析

马病管理系统的开发也是有对应的流程,开发之前必须要进行用户功能需求的分析,最后根据功能需求进行网站设计还有数据库相关数据的设计工作,此次开发的马病管理系统开发流程如图3.1所示。

图3.1 系统开发流程图

系统开发完成之后会给用户提供登录入口,在这个界面用户输入的信息会得到验证,通过验证之后才能进去马病管理系统的访问主界面,系统登录执行流程如下:

图3.2 系统执行流程图

3.3系统功能需求分析

系统的开发离不开前期的需求分析,这个阶段就是让程序员知道自己该做什么事情,在进行需求分析的时候,着重点就是用户对系统的功能要求,这个阶段要是分析得很到位,系统开发出来投入使用时,用户就会发现系统的功能跟用户需求保持一致,程序稳定性也是达标的,可以说需求分析是决定系统开发成败的关键,它主要就是把现实世界进行抽象化,然后把抽象化的对象用来构建模型。

马病管理系统的受益群体主要是工作人员,该网站能够方便使用者进行数据信息的查找和管理工作,本次开发的网站我们设计的界面展示主要分为管理员界面以及用户界面,具体界面的功能分布如下。

马病管理系统管理员可以管理用户的基本信息,可以管理用户信息,可以管理用户信息等。

3.4 系统非功能需求分析

(1)完整性需求

本次开发的马病管理系统里面记录的数据信息不能保持为空,并且数据信息一定要核对正确才行,系统里面数据之间存在的联系不能出错,不能够张冠李戴,数据表里面同一数据在不同数据表里面的显示内容要一样。

(2)性能需求

用户在操作马病管理系统的各个部分内容时,弹出的页面响应时间不能太长,最好控制在三秒钟以内,最大限制值就是四秒,这个是给用户一个好的程序体验。并且系统还要能够承载多人同时在线进行马病管理系统的访问操作。

(3)界面需求

马病管理系统界面设计上面应该考虑到用户日常操作习惯,比如导航栏的设计不能在右边,这个完全违背了用户使用网站的操作习惯,同时功能导航的字体以及颜色应该比较显眼,方便用户容易找寻,避免用户在进行功能操作上面浪费太多时间。

(4)安全性需求

马病管理系统的安全性要有保证,给用户一种可靠,可以信赖的感觉,系统在运行过程中,不能总是出错,与用户进行功能界面交互时,要及时给出反馈信息,另外系统要设置登录窗口,让不是系统的用户不可以进行系统功能界面的访问操作。系统用户也要经过用户名密码的填写操作,才可以进入系统主界面,这样就可以保障系统数据信息处于一种安全状态。

第四章 系统设计

4.1 总体功能

马病管理系统是根据需求定制开发,开发软件选用Myeclipse平台配合MySQL数据库进行开发环境的搭建操作,网站采用WEB应用程序中最流行的B/S结构进行开发,用户访问系统数据仅仅需要在客户端安装谷歌浏览器或者是当下常用浏览器就可以访问网站内容。

4.2 系统模块设计

马病管理系统系统在进行系统中功能模块的划分时,采用层次图来进行表示。层次图具有树形结构,它能使用矩形框来描绘数据信息。顶层代表的数据结构很完整,顶层下面的矩形框表示的数据就是子集数据,当然处于最下面的矩形框就是不能再进行细分的数据元素了,使用层次方框图描述系统功能能让用户一目了然,能够明白系统的功能,以及对应功能板块下面的子功能都可以清楚领会。马病管理系统分为管理员和用户两部分操作角色,下面将对他们的功能进行阐述。

管理员可以管理用户的基本信息,可以管理等功能。管理员功能结构图如下:

马病管理系统

系个人信息管理

管员工管理

管马病收藏管理

管马病留言管理

大马病管理

修个人信息修改

修改密码

新马病新增

是马病修改

删马病删除

删马病留言删除

马病留言新增

马病留言回复

删员工删除

新员工新增

修员工修改

用马病收藏新增

用马病收藏修改

用马病收藏删除

管公告管理

新公告新增

吸公告修改

删公告删除

图4.1 管理员功能结构图

4.3 数据库设计

开发一个系统也需要提前设计数据库。这里的数据库是相关数据的集合,存储在一起的这些数据也是按照一定的组织方式进行的。目前,数据库能够服务于多种应用程序,则是源于它存储方式最佳,具备数据冗余率低的优势。虽然数据库为程序提供信息存储服务,但它与程序之间也可以保持较高的独立性。总而言之,数据库经历了很长一段时间的发展,从最初的不为人知,到现在的人尽皆知,其相关技术也越发成熟,同时也拥有着坚实的理论基础。

4.3.1 数据库概念设计

这部分内容需要借助数据库关系图来完成,也需要使用专门绘制数据库关系图的工具,比如Visio工具就可以设计E-R图(数据库关系图)。设计数据库,也需要按照设计的流程进行,首先还是要根据需求完成实体的确定,分析实体具有的特征,还有对实体间的关联关系进行确定。最后才是使用E-R模型的表示方法,绘制本系统的E-R图。不管是使用亿图软件,还是Visio工具,对于E-R模型的表示符号都一样,通常矩形代表实体,实体间存在的关系用菱形符号表示,实体的属性也就是实体的特征用符号椭圆表示。最后使用直线将矩形,菱形和椭圆等符号连接起来。接下来就开始对本系统的E-R图进行绘制。

(1)下图是论坛实体和其具备的属性。

论坛 图4.1 论坛实体属性图

(2)下图是用户实体和其具备的属性。

用户 图4.2 用户实体属性图

(3)下图是公告信息实体和其具备的属性。

公告信息 图4.3 公告信息实体属性图

(4)下图是员工实体和其具备的属性。

员工 图4.4 员工实体属性图

(5)下图是马病实体和其具备的属性。

马病 图4.5 马病实体属性图

(6)下图是马病收藏实体和其具备的属性。

马病收藏 图4.6 马病收藏实体属性图

(7)下图是马病留言实体和其具备的属性。

马病留言 图4.7 马病留言实体属性图

4.3.3 数据库表设计

数据库里面的数据表存放的就是各种数据记录,我们在进行系统增删改查操作时,其实也是在对应数据表里面进行的增删改查操作,一个好的数据库能够缩短信息处理时间,所以说数据库的设计工作不容小觑,数据库里面设置哪些表,表里面的字段设计以及字段类型和字段长度等信息都要考虑周到才行,比如时间这个字段,它的数据类型就不能是int型,不然在系统操作中就会弹出输入数据格式不符合要求的报错提示。下面简单介绍马病管理系统的一些数据表。

表4.1字典表

序号列名数据类型说明允许空
1IdIntid
2dic_codeString字段
3dic_nameString字段名
4code_indexInteger编码
5index_nameString编码名字
6super_idInteger父字段id
7beizhuString备注
8create_timeDate创建时间

表4.2论坛表

序号列名数据类型说明允许空
1IdIntid
2forum_nameString帖子标题
3yonghu_idInteger用户
4yuangong_idInteger员工
5users_idInteger管理员
6forum_contentString发布内容
7super_idsInteger父id
8forum_typesInteger帖子类型
9forum_state_typesInteger帖子状态
10insert_timeDate发帖时间
11update_timeDate修改时间
12create_timeDate创建时间

表4.3公告信息表

序号列名数据类型说明允许空
1IdIntid
2gonggao_nameString公告名称
3gonggao_photoString公告图片
4gonggao_typesInteger公告类型
5insert_timeDate公告发布时间
6gonggao_contentString公告详情
7create_timeDate创建时间

表4.4马病表

序号列名数据类型说明允许空
1IdIntid
2mabing_uuid_numberString马病编号
3mabing_nameString马病名称
4mabing_photoString马病照片
5mabing_typesInteger病因类型
6zhengzhuang_textString基本症状
7zhiliaofangan_textString治疗方案
8yufangfangan_textString预防方案
9mabing_clicknumInteger点击次数
10shangxia_typesInteger是否上架
11mabing_deleteInteger逻辑删除
12mabing_contentString马病详细介绍
13insert_timeDate添加时间
14update_timeDate最后更新时间
15create_timeDate创建时间

表4.5马病收藏表

序号列名数据类型说明允许空
1IdIntid
2mabing_idInteger马病
3yonghu_idInteger用户
4mabing_collection_typesInteger类型
5insert_timeDate收藏时间
6create_timeDate创建时间

表4.6马病留言表

序号列名数据类型说明允许空
1IdIntid
2mabing_idInteger马病
3yonghu_idInteger用户
4mabing_liuyan_textString留言内容
5insert_timeDate留言时间
6reply_textString回复内容
7update_timeDate回复时间
8create_timeDate创建时间

表4.7用户表

序号列名数据类型说明允许空
1IdIntid
2yonghu_nameString用户姓名
3yonghu_phoneString用户手机号
4yonghu_id_numberString用户身份证号
5yonghu_photoString用户头像
6yonghu_emailString电子邮箱
7create_timeDate创建时间

表4.8员工表

序号列名数据类型说明允许空
1IdIntid
2yuangong_nameString员工姓名
3yuangong_phoneString员工手机号
4yuangong_photoString员工头像
5yuangong_emailString电子邮箱
6create_timeDate创建时间

表4.9管理员表

序号列名数据类型说明允许空
1IdIntid
2usernameString用户名
3passwordString密码
4roleString角色
5addtimeDate新增时间

第五章 系统实现

5.1 管理员功能模块的实现

5.1.1 马病列表

如图5.1显示的就是马病列表页面,此页面提供给管理员的功能有:查看马病、新增马病、修改马病、删除马病等。

图5.1 马病列表页面

5.1.2 公告信息管理

管理员可以对公告信息的基本信息进行管理,可以新增公告信息,可以对错误的公告信息进行修改,可以对无效的公告信息进行删除。公告信息管理界面如图5.2所示。

图5.2 公告信息管理页面

5.1.3 公告类型管理

公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。下图就是公告类型管理页面。公告类型管理界面如图5.3所示。

图5.3公告类型管理界面

YuangongController.java

package com.controller;

import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;

import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;

/**
 * 员工
 * 后端接口
 * @author
 * @email
*/
@RestController
@Controller
@RequestMapping("/yuangong")
public class YuangongController {
    private static final Logger logger = LoggerFactory.getLogger(YuangongController.class);

    @Autowired
    private YuangongService yuangongService;


    @Autowired
    private TokenService tokenService;
    @Autowired
    private DictionaryService dictionaryService;

    //级联表service

    @Autowired
    private YonghuService yonghuService;


    /**
    * 后端列表
    */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永不会进入");
        else if("用户".equals(role))
            params.put("yonghuId",request.getSession().getAttribute("userId"));
        else if("员工".equals(role))
            params.put("yuangongId",request.getSession().getAttribute("userId"));
        if(params.get("orderBy")==null || params.get("orderBy")==""){
            params.put("orderBy","id");
        }
        PageUtils page = yuangongService.queryPage(params);

        //字典表数据转换
        List<YuangongView> list =(List<YuangongView>)page.getList();
        for(YuangongView c:list){
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(c, request);
        }
        return R.ok().put("data", page);
    }

    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        YuangongEntity yuangong = yuangongService.selectById(id);
        if(yuangong !=null){
            //entity转view
            YuangongView view = new YuangongView();
            BeanUtils.copyProperties( yuangong , view );//把实体数据重构到view中

            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody YuangongEntity yuangong, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,yuangong:{}",this.getClass().getName(),yuangong.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永远不会进入");

        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if(yuangongEntity==null){
            yuangong.setCreateTime(new Date());
            yuangong.setPassword("123456");
            yuangongService.insert(yuangong);
            return R.ok();
        }else {
            return R.error(511,"账户或者员工手机号已经被使用");
        }
    }

    /**
    * 后端修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody YuangongEntity yuangong, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,yuangong:{}",this.getClass().getName(),yuangong.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
//        if(false)
//            return R.error(511,"永远不会进入");
        //根据字段查询是否有相同数据
        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .notIn("id",yuangong.getId())
            .andNew()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if("".equals(yuangong.getYuangongPhoto()) || "null".equals(yuangong.getYuangongPhoto())){
                yuangong.setYuangongPhoto(null);
        }
        if(yuangongEntity==null){
            yuangongService.updateById(yuangong);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"账户或者员工手机号已经被使用");
        }
    }

    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        yuangongService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        try {
            List<YuangongEntity> yuangongList = new ArrayList<>();//上传的东西
            Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
            Date date = new Date();
            int lastIndexOf = fileName.lastIndexOf(".");
            if(lastIndexOf == -1){
                return R.error(511,"该文件没有后缀");
            }else{
                String suffix = fileName.substring(lastIndexOf);
                if(!".xls".equals(suffix)){
                    return R.error(511,"只支持后缀为xls的excel文件");
                }else{
                    URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
                    File file = new File(resource.getFile());
                    if(!file.exists()){
                        return R.error(511,"找不到上传文件,请联系管理员");
                    }else{
                        List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
                        dataList.remove(0);//删除第一行,因为第一行是提示
                        for(List<String> data:dataList){
                            //循环
                            YuangongEntity yuangongEntity = new YuangongEntity();
//                            yuangongEntity.setUsername(data.get(0));                    //账户 要改的
//                            //yuangongEntity.setPassword("123456");//密码
//                            yuangongEntity.setYuangongName(data.get(0));                    //员工姓名 要改的
//                            yuangongEntity.setYuangongPhone(data.get(0));                    //员工手机号 要改的
//                            yuangongEntity.setYuangongPhoto("");//照片
//                            yuangongEntity.setSexTypes(Integer.valueOf(data.get(0)));   //性别 要改的
//                            yuangongEntity.setYuangongEmail(data.get(0));                    //电子邮箱 要改的
//                            yuangongEntity.setCreateTime(date);//时间
                            yuangongList.add(yuangongEntity);


                            //把要查询是否重复的字段放入map中
                                //账户
                                if(seachFields.containsKey("username")){
                                    List<String> username = seachFields.get("username");
                                    username.add(data.get(0));//要改的
                                }else{
                                    List<String> username = new ArrayList<>();
                                    username.add(data.get(0));//要改的
                                    seachFields.put("username",username);
                                }
                                //员工手机号
                                if(seachFields.containsKey("yuangongPhone")){
                                    List<String> yuangongPhone = seachFields.get("yuangongPhone");
                                    yuangongPhone.add(data.get(0));//要改的
                                }else{
                                    List<String> yuangongPhone = new ArrayList<>();
                                    yuangongPhone.add(data.get(0));//要改的
                                    seachFields.put("yuangongPhone",yuangongPhone);
                                }
                        }

                        //查询是否重复
                         //账户
                        List<YuangongEntity> yuangongEntities_username = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("username", seachFields.get("username")));
                        if(yuangongEntities_username.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_username){
                                repeatFields.add(s.getUsername());
                            }
                            return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                         //员工手机号
                        List<YuangongEntity> yuangongEntities_yuangongPhone = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("yuangong_phone", seachFields.get("yuangongPhone")));
                        if(yuangongEntities_yuangongPhone.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_yuangongPhone){
                                repeatFields.add(s.getYuangongPhone());
                            }
                            return R.error(511,"数据库的该表中的 [员工手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                        yuangongService.insertBatch(yuangongList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            return R.error(511,"批量插入数据异常,请联系管理员");
        }
    }


    /**
    * 登录
    */
    @IgnoreAuth
    @RequestMapping(value = "/login")
    public R login(String username, String password, String captcha, HttpServletRequest request) {
        YuangongEntity yuangong = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("username", username));
        if(yuangong==null || !yuangong.getPassword().equals(password))
            return R.error("账号或密码不正确");
        //  // 获取监听器中的字典表
        // ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
        // Map<String, Map<Integer, String>> dictionaryMap= (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
        // Map<Integer, String> role_types = dictionaryMap.get("role_types");
        // role_types.get(.getRoleTypes());
        String token = tokenService.generateToken(yuangong.getId(),username, "yuangong", "员工");
        R r = R.ok();
        r.put("token", token);
        r.put("role","员工");
        r.put("username",yuangong.getYuangongName());
        r.put("tableName","yuangong");
        r.put("userId",yuangong.getId());
        return r;
    }

    /**
    * 注册
    */
    @IgnoreAuth
    @PostMapping(value = "/register")
    public R register(@RequestBody YuangongEntity yuangong){
//    	ValidatorUtils.validateEntity(user);
        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            ;
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if(yuangongEntity != null)
            return R.error("账户或者员工手机号已经被使用");
        yuangong.setCreateTime(new Date());
        yuangongService.insert(yuangong);
        return R.ok();
    }

    /**
     * 重置密码
     */
    @GetMapping(value = "/resetPassword")
    public R resetPassword(Integer  id){
        YuangongEntity yuangong = new YuangongEntity();
        yuangong.setPassword("123456");
        yuangong.setId(id);
        yuangongService.updateById(yuangong);
        return R.ok();
    }


    /**
     * 忘记密码
     */
    @IgnoreAuth
    @RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request) {
        YuangongEntity yuangong = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("username", username));
        if(yuangong!=null){
            yuangong.setPassword("123456");
            boolean b = yuangongService.updateById(yuangong);
            if(!b){
               return R.error();
            }
        }else{
           return R.error("账号不存在");
        }
        return R.ok();
    }


    /**
    * 获取用户的session用户信息
    */
    @RequestMapping("/session")
    public R getCurrYuangong(HttpServletRequest request){
        Integer id = (Integer)request.getSession().getAttribute("userId");
        YuangongEntity yuangong = yuangongService.selectById(id);
        if(yuangong !=null){
            //entity转view
            YuangongView view = new YuangongView();
            BeanUtils.copyProperties( yuangong , view );//把实体数据重构到view中

            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }
    }


    /**
    * 退出
    */
    @GetMapping(value = "logout")
    public R logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return R.ok("退出成功");
    }




    /**
    * 前端列表
    */
    @IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));

        // 没有指定排序字段就默认id倒序
        if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
            params.put("orderBy","id");
        }
        PageUtils page = yuangongService.queryPage(params);

        //字典表数据转换
        List<YuangongView> list =(List<YuangongView>)page.getList();
        for(YuangongView c:list)
            dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
        return R.ok().put("data", page);
    }

    /**
    * 前端详情
    */
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        YuangongEntity yuangong = yuangongService.selectById(id);
            if(yuangong !=null){


                //entity转view
                YuangongView view = new YuangongView();
                BeanUtils.copyProperties( yuangong , view );//把实体数据重构到view中

                //修改对应字典表字段
                dictionaryService.dictionaryConvert(view, request);
                return R.ok().put("data", view);
            }else {
                return R.error(511,"查不到数据");
            }
    }


    /**
    * 前端保存
    */
    @RequestMapping("/add")
    public R add(@RequestBody YuangongEntity yuangong, HttpServletRequest request){
        logger.debug("add方法:,,Controller:{},,yuangong:{}",this.getClass().getName(),yuangong.toString());
        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            ;
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if(yuangongEntity==null){
            yuangong.setCreateTime(new Date());
        yuangong.setPassword("123456");
        yuangongService.insert(yuangong);
            return R.ok();
        }else {
            return R.error(511,"账户或者员工手机号已经被使用");
        }
    }


}

MabingCollectionController.java

package com.controller;

import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;

import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;

/**
 * 马病收藏
 * 后端接口
 * @author
 * @email
*/
@RestController
@Controller
@RequestMapping("/mabingCollection")
public class MabingCollectionController {
    private static final Logger logger = LoggerFactory.getLogger(MabingCollectionController.class);

    @Autowired
    private MabingCollectionService mabingCollectionService;


    @Autowired
    private TokenService tokenService;
    @Autowired
    private DictionaryService dictionaryService;

    //级联表service
    @Autowired
    private MabingService mabingService;
    @Autowired
    private YonghuService yonghuService;

    @Autowired
    private YuangongService yuangongService;


    /**
    * 后端列表
    */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永不会进入");
        else if("用户".equals(role))
            params.put("yonghuId",request.getSession().getAttribute("userId"));
        else if("员工".equals(role))
            params.put("yuangongId",request.getSession().getAttribute("userId"));
        if(params.get("orderBy")==null || params.get("orderBy")==""){
            params.put("orderBy","id");
        }
        PageUtils page = mabingCollectionService.queryPage(params);

        //字典表数据转换
        List<MabingCollectionView> list =(List<MabingCollectionView>)page.getList();
        for(MabingCollectionView c:list){
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(c, request);
        }
        return R.ok().put("data", page);
    }

    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        MabingCollectionEntity mabingCollection = mabingCollectionService.selectById(id);
        if(mabingCollection !=null){
            //entity转view
            MabingCollectionView view = new MabingCollectionView();
            BeanUtils.copyProperties( mabingCollection , view );//把实体数据重构到view中

                //级联表
                MabingEntity mabing = mabingService.selectById(mabingCollection.getMabingId());
                if(mabing != null){
                    BeanUtils.copyProperties( mabing , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setMabingId(mabing.getId());
                }
                //级联表
                YonghuEntity yonghu = yonghuService.selectById(mabingCollection.getYonghuId());
                if(yonghu != null){
                    BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createTime", "insertTime", "updateTime"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setYonghuId(yonghu.getId());
                }
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view, request);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody MabingCollectionEntity mabingCollection, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,mabingCollection:{}",this.getClass().getName(),mabingCollection.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永远不会进入");
        else if("用户".equals(role))
            mabingCollection.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));

        Wrapper<MabingCollectionEntity> queryWrapper = new EntityWrapper<MabingCollectionEntity>()
            .eq("mabing_id", mabingCollection.getMabingId())
            .eq("yonghu_id", mabingCollection.getYonghuId())
            .eq("mabing_collection_types", mabingCollection.getMabingCollectionTypes())
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        MabingCollectionEntity mabingCollectionEntity = mabingCollectionService.selectOne(queryWrapper);
        if(mabingCollectionEntity==null){
            mabingCollection.setInsertTime(new Date());
            mabingCollection.setCreateTime(new Date());
            mabingCollectionService.insert(mabingCollection);
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
    * 后端修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody MabingCollectionEntity mabingCollection, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,mabingCollection:{}",this.getClass().getName(),mabingCollection.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
//        if(false)
//            return R.error(511,"永远不会进入");
//        else if("用户".equals(role))
//            mabingCollection.setYonghuId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));
        //根据字段查询是否有相同数据
        Wrapper<MabingCollectionEntity> queryWrapper = new EntityWrapper<MabingCollectionEntity>()
            .notIn("id",mabingCollection.getId())
            .andNew()
            .eq("mabing_id", mabingCollection.getMabingId())
            .eq("yonghu_id", mabingCollection.getYonghuId())
            .eq("mabing_collection_types", mabingCollection.getMabingCollectionTypes())
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        MabingCollectionEntity mabingCollectionEntity = mabingCollectionService.selectOne(queryWrapper);
        if(mabingCollectionEntity==null){
            mabingCollectionService.updateById(mabingCollection);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        mabingCollectionService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        try {
            List<MabingCollectionEntity> mabingCollectionList = new ArrayList<>();//上传的东西
            Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
            Date date = new Date();
            int lastIndexOf = fileName.lastIndexOf(".");
            if(lastIndexOf == -1){
                return R.error(511,"该文件没有后缀");
            }else{
                String suffix = fileName.substring(lastIndexOf);
                if(!".xls".equals(suffix)){
                    return R.error(511,"只支持后缀为xls的excel文件");
                }else{
                    URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
                    File file = new File(resource.getFile());
                    if(!file.exists()){
                        return R.error(511,"找不到上传文件,请联系管理员");
                    }else{
                        List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
                        dataList.remove(0);//删除第一行,因为第一行是提示
                        for(List<String> data:dataList){
                            //循环
                            MabingCollectionEntity mabingCollectionEntity = new MabingCollectionEntity();
//                            mabingCollectionEntity.setMabingId(Integer.valueOf(data.get(0)));   //马病 要改的
//                            mabingCollectionEntity.setYonghuId(Integer.valueOf(data.get(0)));   //用户 要改的
//                            mabingCollectionEntity.setMabingCollectionTypes(Integer.valueOf(data.get(0)));   //类型 要改的
//                            mabingCollectionEntity.setInsertTime(date);//时间
//                            mabingCollectionEntity.setCreateTime(date);//时间
                            mabingCollectionList.add(mabingCollectionEntity);


                            //把要查询是否重复的字段放入map中
                        }

                        //查询是否重复
                        mabingCollectionService.insertBatch(mabingCollectionList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            return R.error(511,"批量插入数据异常,请联系管理员");
        }
    }





    /**
    * 前端列表
    */
    @IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));

        // 没有指定排序字段就默认id倒序
        if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
            params.put("orderBy","id");
        }
        PageUtils page = mabingCollectionService.queryPage(params);

        //字典表数据转换
        List<MabingCollectionView> list =(List<MabingCollectionView>)page.getList();
        for(MabingCollectionView c:list)
            dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
        return R.ok().put("data", page);
    }

    /**
    * 前端详情
    */
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        MabingCollectionEntity mabingCollection = mabingCollectionService.selectById(id);
            if(mabingCollection !=null){


                //entity转view
                MabingCollectionView view = new MabingCollectionView();
                BeanUtils.copyProperties( mabingCollection , view );//把实体数据重构到view中

                //级联表
                    MabingEntity mabing = mabingService.selectById(mabingCollection.getMabingId());
                if(mabing != null){
                    BeanUtils.copyProperties( mabing , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setMabingId(mabing.getId());
                }
                //级联表
                    YonghuEntity yonghu = yonghuService.selectById(mabingCollection.getYonghuId());
                if(yonghu != null){
                    BeanUtils.copyProperties( yonghu , view ,new String[]{ "id", "createDate"});//把级联的数据添加到view中,并排除id和创建时间字段
                    view.setYonghuId(yonghu.getId());
                }
                //修改对应字典表字段
                dictionaryService.dictionaryConvert(view, request);
                return R.ok().put("data", view);
            }else {
                return R.error(511,"查不到数据");
            }
    }


    /**
    * 前端保存
    */
    @RequestMapping("/add")
    public R add(@RequestBody MabingCollectionEntity mabingCollection, HttpServletRequest request){
        logger.debug("add方法:,,Controller:{},,mabingCollection:{}",this.getClass().getName(),mabingCollection.toString());
        Wrapper<MabingCollectionEntity> queryWrapper = new EntityWrapper<MabingCollectionEntity>()
            .eq("mabing_id", mabingCollection.getMabingId())
            .eq("yonghu_id", mabingCollection.getYonghuId())
            .eq("mabing_collection_types", mabingCollection.getMabingCollectionTypes())
            ;
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        MabingCollectionEntity mabingCollectionEntity = mabingCollectionService.selectOne(queryWrapper);
        if(mabingCollectionEntity==null){
            mabingCollection.setInsertTime(new Date());
            mabingCollection.setCreateTime(new Date());
        mabingCollectionService.insert(mabingCollection);
            return R.ok();
        }else {
            return R.error(511,"您已经收藏过了");
        }
    }


}

DictionaryServiceImpl.java
package com.service.impl;

import com.utils.StringUtil;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.*;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import com.utils.PageUtils;
import com.utils.Query;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import com.dao.DictionaryDao;
import com.entity.DictionaryEntity;
import com.service.DictionaryService;
import com.entity.view.DictionaryView;

/**
 * 字典 服务实现类
 */
@Service("dictionaryService")
@Transactional
public class DictionaryServiceImpl extends ServiceImpl<DictionaryDao, DictionaryEntity> implements DictionaryService {

    @Override
    public PageUtils queryPage(Map<String,Object> params) {
        if(params != null && (params.get("limit") == null || params.get("page") == null)){
            params.put("page","1");
            params.put("limit","10");
        }
        Page<DictionaryView> page =new Query<DictionaryView>(params).getPage();
        page.setRecords(baseMapper.selectListView(page,params));
        return new PageUtils(page);
    }

     /**
     * 赋值给字典表
     * @param obj view对象
     */
    public void dictionaryConvert(Object obj, HttpServletRequest request) {
        try {
            if (obj == null) return;
            //当前view和entity中的所有types的字段
            List<String> fieldNameList = new ArrayList<>();
            Class tempClass = obj.getClass();
            while (tempClass !=null) {
                Field[] declaredFields = tempClass.getDeclaredFields();
                for (Field f : declaredFields) {
                    f.setAccessible(true);
                    if (f.getType().getName().equals("java.lang.Integer") && f.getName().contains("Types")) {
                        fieldNameList.add(f.getName());
                    }
                }
                tempClass = tempClass.getSuperclass(); //得到父类,然后赋给自己
            }

            // 获取监听器中的字典表
//            ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
            ServletContext servletContext = request.getServletContext();
            Map<String, Map<Integer, String>> dictionaryMap= (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");

            //通过Types的值给Value字段赋值
            for (String s : fieldNameList) {
                Field types = null;
                if(hasField(obj.getClass(),s)){
                    //判断view中有没有这个字段,有就通过反射取出字段
                    types= obj.getClass().getDeclaredField(s);//获取Types私有字段
                }else{
                    //本表中没有这个字段,说明它是父表中的字段,也就是entity中的字段,从entity中取值
                    types=obj.getClass().getSuperclass().getDeclaredField(s);
                }
                Field value = obj.getClass().getDeclaredField(s.replace("Types", "Value"));//获取value私有字段
                //设置权限
                types.setAccessible(true);
                value.setAccessible(true);

                //赋值
                if (StringUtil.isNotEmpty(String.valueOf(types.get(obj)))) { //types的值不为空
                    int i = Integer.parseInt(String.valueOf(types.get(obj)));//type
                    //把s1字符中的所有大写转小写,并在前面加 _
                    char[] chars = s.toCharArray();
                    StringBuffer sbf = new StringBuffer();
                    for(int  b=0; b< chars.length; b++){
                        char ch = chars[b];
                        if(ch <= 90 && ch >= 65){
                            sbf.append("_");
                            ch += 32;
                        }
                        sbf.append(ch);
                    }
                    String s2 = dictionaryMap.get(sbf.toString()).get(i);
                    value.set(obj, s2);
                } else {
                    new Exception("字典表赋值出现问题::::"+value.getName());
                    value.set(obj, "");
                }
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 判断本实体有没有这个字段
     * @param c
     * @param fieldName
     * @return
     */
    public boolean hasField(Class c, String fieldName){
        Field[] fields = c.getDeclaredFields();

        for (Field f : fields) {
            if (fieldName.equals(f.getName())) {
                return true;

            }

        }

        return false;
    }

}

list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-cn">


<head>
    <%@ include file="../../static/head.jsp" %>
    <!-- font-awesome -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font-awesome.min.css">

    <!-- layui -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/resources/layui/layui.js"></script>
</head>
<style>

</style>
<body>
<!-- Pre Loader -->
<div class="loading">
    <div class="spinner">
        <div class="double-bounce1"></div>
        <div class="double-bounce2"></div>
    </div>
</div>
<!--/Pre Loader -->
<div class="wrapper">
    <!-- Page Content -->
    <div id="content">
        <!-- Top Navigation -->
        <%@ include file="../../static/topNav.jsp" %>
        <!-- Menu -->
        <div class="container menu-nav">
            <nav class="navbar navbar-expand-lg lochana-bg text-white">
                <button class="navbar-toggler" type="button" data-toggle="collapse"
                        data-target="#navbarSupportedContent"
                        aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="ti-menu text-white"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul id="navUl" class="navbar-nav mr-auto">
                    </ul>
                </div>
            </nav>
        </div>
        <!-- /Menu -->
        <!-- Breadcrumb -->
        <!-- Page Title -->
        <div class="container mt-0">
            <div class="row breadcrumb-bar">
                <div class="col-md-6">
                    <h3 class="block-title">病因类型管理</h3>
                </div>
                <div class="col-md-6">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a href="${pageContext.request.contextPath}/index.jsp">
                                <span class="ti-home"></span>
                            </a>
                        </li>
                        <li class="breadcrumb-item">病因类型管理</li>
                        <li class="breadcrumb-item active">病因类型列表</li>
                    </ol>
                </div>
            </div>
        </div>
        <!-- /Page Title -->

        <!-- /Breadcrumb -->
        <!-- Main Content -->
        <div class="container">

            <div class="row">
                <!-- Widget Item -->
                <div class="col-md-12">
                    <div class="widget-area-2 lochana-box-shadow">
                        <h3 class="widget-title">病因类型列表</h3>
                        <div class="table-responsive mb-3">
                            <div class="col-sm-12">
                                <div class="layui-inline" style="margin-bottom: 10px;">
                                    病因类型名称
                                    <div class="layui-input-inline">
                                        <input type="text" id="indexNameSearch" style="width: 140px;" class="form-control form-control-sm"
                                               placeholder="病因类型名称" aria-controls="tableId">
                                    </div>
                                </div>

                                <div class="layui-inline" style="margin-left: 30px;margin-bottom: 10px;">
                                    <button onclick="search()" type="button" class="btn btn-primary">查询</button>
                                    <button onclick="add()" type="button" class="btn btn-success 新增">添加</button>
                                    <button onclick="deleteMore()" type="button" class="btn btn-danger 删除">批量删除</button>
                                </div>
                            </div>
                            <table id="tableId" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th class="no-sort" style="min-width: 35px;">
                                        <div class="custom-control custom-checkbox">
                                            <input class="custom-control-input" type="checkbox" id="select-all"
                                                   onclick="chooseAll()">
                                            <label class="custom-control-label" for="select-all"></label>
                                        </div>
                                    </th>

                                    <th >病因类型编码</th>
                                    <th >病因类型名称</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="thisTbody">
                                </tbody>
                            </table>
                            <div class="col-md-6 col-sm-3">
                                <div class="dataTables_length" id="tableId_length">

                                    <select name="tableId_length" aria-controls="tableId" id="selectPageSize"
                                            onchange="changePageSize()">
                                        <option value="10">10</option>
                                        <option value="25">25</option>
                                        <option value="50">50</option>
                                        <option value="100">100</option>
                                    </select>
                                    条 每页

                                </div>
                            </div>
                            <nav aria-label="Page navigation example">
                                <ul class="pagination justify-content-end">
                                    <li class="page-item" id="tableId_previous" onclick="pageNumChange('pre')">
                                        <a class="page-link" href="#" tabindex="-1">上一页</a>
                                    </li>

                                    <li class="page-item" id="tableId_next" onclick="pageNumChange('next')">
                                        <a class="page-link" href="#">下一页</a>
                                    </li>
                                </ul>
                            </nav>
                        </div>
                    </div>
                </div>
                <!-- /Widget Item -->
            </div>
        </div>
        <!-- /Main Content -->

    </div>
    <!-- /Page Content -->
</div>
<!-- Back to Top -->
<a id="back-to-top" href="#" class="back-to-top">
    <span class="ti-angle-up"></span>
</a>
<!-- /Back to Top -->
<%@ include file="../../static/foot.jsp" %>
<script language="javascript" type="text/javascript"
        src="${pageContext.request.contextPath}/resources/My97DatePicker/WdatePicker.js"></script>

<script>
    <%@ include file="../../utils/menu.jsp"%>
            <%@ include file="../../static/setMenu.js"%>
            <%@ include file="../../utils/baseUrl.jsp"%>
            <%@ include file="../../static/getRoleButtons.js"%>
            <%@ include file="../../static/crossBtnControl.js"%>
    var tableName = "dictionaryMabing";
    var pageType = "list";
    var searchForm = {key: ""};
    var pageIndex = 1;
    var pageSize = 10;
    var totalPage = 0;
    var dataList = [];
    var sortColumn = '';
    var sortOrder = '';
    var ids = [];
    var checkAll = false;



    function init() {
        // 满足条件渲染提醒接口
    }

    // 改变每页记录条数
    function changePageSize() {
        var selection = document.getElementById('selectPageSize');
        var index = selection.selectedIndex;
        pageSize = selection.options[index].value;
        getDataList();
    }



    // 查询
    function search() {
        searchForm = {key: ""};

                     
        //编码名字
        var indexNameSearchInput = $('#indexNameSearch');
        if( indexNameSearchInput != null){
            if (indexNameSearchInput.val() != null && indexNameSearchInput.val() != '') {
                searchForm.indexName = $('#indexNameSearch').val();
            }
        }
                getDataList();
    }

    // 获取数据列表
    function getDataList() {
        http("dictionary/page", "GET", {
            page: pageIndex,
            limit: pageSize,
            sort: sortColumn,
            order: sortOrder,
            //本表的
            dicCode: "mabing_types",//编码名字
            dicName: "病因类型",//汉字名字
            indexName:searchForm.indexName,
            //级联表的

        }, (res) => {
            if(res.code == 0) {
                clear();
                $("#thisTbody").html("");
                dataList = res.data.list;
                totalPage = res.data.totalPage;
                for (var i = 0; i < dataList.length; i++) { //遍历一下表格数据  
                    var trow = setDataRow(dataList[i], i); //定义一个方法,返回tr数据 
                    $('#thisTbody').append(trow);
                }
                pagination(); //渲染翻页组件
                getRoleButtons();// 权限按钮控制
            }
        });
    }

    // 渲染表格数据
    function setDataRow(item, number) {
        //创建行 
        var row = document.createElement('tr');
        row.setAttribute('class', 'useOnce');
        //创建勾选框
        var checkbox = document.createElement('td');
        var checkboxDiv = document.createElement('div');
        checkboxDiv.setAttribute("class", "custom-control custom-checkbox");
        var checkboxInput = document.createElement('input');
        checkboxInput.setAttribute("class", "custom-control-input");
        checkboxInput.setAttribute("type", "checkbox");
        checkboxInput.setAttribute('name', 'chk');
        checkboxInput.setAttribute('value', item.id);
        checkboxInput.setAttribute("id", number);
        checkboxDiv.appendChild(checkboxInput);
        var checkboxLabel = document.createElement('label');
        checkboxLabel.setAttribute("class", "custom-control-label");
        checkboxLabel.setAttribute("for", number);
        checkboxDiv.appendChild(checkboxLabel);
        checkbox.appendChild(checkboxDiv);
        row.appendChild(checkbox)


        //编码
        var codeIndexCell = document.createElement('td');
        codeIndexCell.innerHTML = item.codeIndex;
        row.appendChild(codeIndexCell);

        //类型
        var indexNameCell = document.createElement('td');
        indexNameCell.innerHTML = item.indexName;
        row.appendChild(indexNameCell);



        //每行按钮
        var btnGroup = document.createElement('td');

        //详情按钮
        var detailBtn = document.createElement('button');
        var detailAttr = "detail(" + item.id + ')';
        detailBtn.setAttribute("type", "button");
        detailBtn.setAttribute("class", "btn btn-info btn-sm 查看");
        detailBtn.setAttribute("onclick", detailAttr);
        detailBtn.innerHTML = "查看"
        btnGroup.appendChild(detailBtn)
        //修改按钮
        var editBtn = document.createElement('button');
        var editAttr = 'edit(' + item.id + ')';
        editBtn.setAttribute("type", "button");
        editBtn.setAttribute("class", "btn btn-warning btn-sm 修改");
        editBtn.setAttribute("onclick", editAttr);
        editBtn.innerHTML = "修改"
        btnGroup.appendChild(editBtn)
        //删除按钮
        var deleteBtn = document.createElement('button');
        var deleteAttr = 'remove(' + item.id + ')';
        deleteBtn.setAttribute("type", "button");
        deleteBtn.setAttribute("class", "btn btn-danger btn-sm 删除");
        deleteBtn.setAttribute("onclick", deleteAttr);
        deleteBtn.innerHTML = "删除"
        btnGroup.appendChild(deleteBtn)

        row.appendChild(btnGroup)
        return row;
    }


    // 翻页
    function pageNumChange(val) {
        if (val == 'pre') {
            pageIndex--;
        } else if (val == 'next') {
            pageIndex++;
        } else {
            pageIndex = val;
        }
        getDataList();
    }

    // 下载
    function download(url) {
        window.open(url);
    }

    // 渲染翻页组件
    function pagination() {
        var beginIndex = pageIndex;
        var endIndex = pageIndex;
        var point = 4;
        //计算页码
        for (var i = 0; i < 3; i++) {
            if (endIndex == totalPage) {
                break;
            }
            endIndex++;
            point--;
        }
        for (var i = 0; i < 3; i++) {
            if (beginIndex == 1) {
                break;
            }
            beginIndex--;
            point--;
        }
        if (point > 0) {
            while (point > 0) {
                if (endIndex == totalPage) {
                    break;
                }
                endIndex++;
                point--;
            }
            while (point > 0) {
                if (beginIndex == 1) {
                    break;
                }
                beginIndex--;
                point--
            }
        }
        // 是否显示 前一页 按钮
        if (pageIndex > 1) {
            $('#tableId_previous').show();
        } else {
            $('#tableId_previous').hide();
        }
        // 渲染页码按钮
        for (var i = beginIndex; i <= endIndex; i++) {
            var pageNum = document.createElement('li');
            pageNum.setAttribute('onclick', "pageNumChange(" + i + ")");
            if (pageIndex == i) {
                pageNum.setAttribute('class', 'paginate_button page-item active useOnce');
            } else {
                pageNum.setAttribute('class', 'paginate_button page-item useOnce');
            }
            var pageHref = document.createElement('a');
            pageHref.setAttribute('class', 'page-link');
            pageHref.setAttribute('href', '#');
            pageHref.setAttribute('aria-controls', 'tableId');
            pageHref.setAttribute('data-dt-idx', i);
            pageHref.setAttribute('tabindex', 0);
            pageHref.innerHTML = i;
            pageNum.appendChild(pageHref);
            $('#tableId_next').before(pageNum);
        }
        // 是否显示 下一页 按钮
        if (pageIndex < totalPage) {
            $('#tableId_next').show();
            $('#tableId_next a').attr('data-dt-idx', endIndex + 1);
        } else {
            $('#tableId_next').hide();
        }
        var pageNumInfo = "当前第 " + pageIndex + " 页,共 " + totalPage + " 页";
        $('#tableId_info').html(pageNumInfo);
    }

    // 跳转到指定页
    function toThatPage() {
        //var index = document.getElementById('pageIndexInput').value;
        if (index < 0 || index > totalPage) {
            alert('请输入正确的页码');
        } else {
            pageNumChange(index);
        }
    }

    // 全选/全不选
    function chooseAll() {
        checkAll = !checkAll;
        var boxs = document.getElementsByName("chk");
        for (var i = 0; i < boxs.length; i++) {
            boxs[i].checked = checkAll;
        }
    }

    // 批量删除
    function deleteMore() {
        ids = []
        var boxs = document.getElementsByName("chk");
        for (var i = 0; i < boxs.length; i++) {
            if (boxs[i].checked) {
                ids.push(boxs[i].value)
            }
        }
        if (ids.length == 0) {
            alert('请勾选要删除的记录');
        } else {
            remove(ids);
        }
    }

    // 删除
    function remove(id) {
        var mymessage = confirm("真的要删除吗?");
        if (mymessage == true) {
            var paramArray = [];
            if (id == ids) {
                paramArray = id;
            } else {
                paramArray.push(id);
            }
            httpJson("dictionary/delete", "POST", paramArray, (res) => {
                if(res.code == 0){
                    getDataList();
                    alert('删除成功');
                }
            });
        } else {
            alert("已取消操作");
        }
    }

    // 用户登出
    <%@ include file="../../static/logout.jsp"%>

    //修改
    function edit(id) {
        window.sessionStorage.setItem('updateId', id)
        window.location.href = "add-or-update.jsp"
    }

    //清除会重复渲染的节点
    function clear() {
        var elements = document.getElementsByClassName('useOnce');
        for (var i = elements.length - 1; i >= 0; i--) {
            elements[i].parentNode.removeChild(elements[i]);
        }
    }

    //添加
    function add() {
        window.sessionStorage.setItem("adddictionary", "adddictionary");
        window.location.href = "add-or-update.jsp"
    }

    //报表
    function graph() {
        window.location.href = "graph.jsp"
    }

    // 查看详情
    function detail(id) {
        window.sessionStorage.setItem("updateId", id);
        window.location.href = "info.jsp";
    }


    $(document).ready(function () {
        //激活翻页按钮
        $('#tableId_previous').attr('class', 'paginate_button page-item previous')
        $('#tableId_next').attr('class', 'paginate_button page-item next')
        //隐藏原生搜索框
        $('#tableId_filter').hide()
        //设置右上角用户名
        $('.dropdown-menu h5').html(window.sessionStorage.getItem('username'))
        //设置项目名
        $('.sidebar-header h3 a').html(projectName)
        setMenu();
        init();

        getDataList();
                                                             
                        
    <%@ include file="../../static/myInfo.js"%>
    });
</script>
</body>

</html>


声明

本博客适用于广泛的学术和教育用途,包括但不限于个人学习、开发设计,产品设计。仅供学习参考,旨在为读者提供深入理解和学术研究的材料。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值