基于Java+springmvc+vue 健康管理系统

2022年05月12日 阅读数:4
这篇文章主要向大家介绍基于Java+springmvc+vue 健康管理系统,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

项目描述:

设计模式架构:MVC、先后端分离javascript

数据库:MySQLcss

是否基于 Maven 环境:是html

数据库表数量:10张左右前端

是否有分页:有分页vue

是否有代码注释:部分java

功能设计:

开发工具:IDEA 201八、navicat for mysql 。mysql

开发语言:java、jdk1.八、mysql5jquery

硬件环境:Win10系统ios

主要技术:mybatis、vue element、mysql等web

主要功能模块:

1.检查项的新增、编辑和删除,有关联信息不能删除。

2.分页查询和条件查询

3.对检查组编辑和所选检查项的修改

项目的搭建:

 

前端代码:

 

<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预定管理
            <small>检查项管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预定管理</el-breadcrumb-item>
            <el-breadcrumb-item>检查项管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="项目编码/项目名称" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>


                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="code" label="项目编码" align="center"></el-table-column>
                <el-table-column prop="name" label="项目名称" align="center"></el-table-column>
                <el-table-column label="适用性别" align="center">
                    <template slot-scope="scope">
                        <span>{
  
  { scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="age" label="适用年龄" align="center"></el-table-column>
                <el-table-column prop="remark" label="项目说明" align="center"></el-table-column>
                <el-table-column label="操做" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增检查项" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="项目编码" prop="code">
                                    <el-input v-model="formData.code"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="项目名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="不限" value="0"></el-option>
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="适用年龄">
                                    <el-input v-model="formData.age"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="类型">
                                    <el-select v-model="formData.type">
                                        <el-option label="检查" value="1"></el-option>
                                        <el-option label="检验" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="价格">
                                    <el-input v-model="formData.price"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="项目说明">
                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="注意事项">
                                    <el-input v-model="formData.attention" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">肯定</el-button>
                    </div>
                </el-dialog>
            </div>


            <!--编辑-->
            <div class="add-form">
                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item  label="项目" prop="id">
                                    <el-input v-model="formData.id"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="项目编码" prop="code">
                                    <el-input v-model="formData.code"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="项目名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="不限" value="0"></el-option>
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="适用年龄">
                                    <el-input v-model="formData.age"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="类型">
                                    <el-select v-model="formData.type">
                                        <el-option label="检查" value="1"></el-option>
                                        <el-option label="检验" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="价格">
                                    <el-input v-model="formData.price"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="项目说明">
                                    <el-input v-model="formData.remark" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="注意事项">
                                    <el-input v-model="formData.attention" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">肯定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展现的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增长表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数,VUE对象初始化完成后自动执行
        created() {

            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                // 数据的校验
                this.$refs['dataEditForm'].validate(val => {
                    if (val == true) {
                        // 发送数据,给后台
                        axios.post("/checkitem/update.do", this.formData).then(res => {
                            // {flag:true,message:"成功!"}
                            if (res.data.flag == true) {
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                this.dialogFormVisible = false;
                            } else {
                                this.$message.error(res.data.message);
                            }
                        });
                    } else {
                        this.$message.error('数据错误,请重写填写!');
                    }
                });
            },
            //添加
            handleAdd() {
                // 数据的校验
                this.$refs['dataAddForm'].validate(val => {
                    if (val == true) {
                        // 发送数据,给后台
                        axios.post("/checkitem/add.do", this.formData).then(res => {
                            // {flag:true,message:"成功!"}
                            if (res.data.flag == true) {
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                this.dialogFormVisible = false;
                            } else {
                                this.$message.error(res.data.message);
                            }
                        });
                    } else {
                        this.$message.error('数据错误,请重写填写!');
                    }
                });


            },
            //分页查询
            findPage() {


                axios.post("/checkitem/findPage.do", this.pagination).then(res => {
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total;

                })
            },
            // 重置表单
            resetForm() {
            },
            // 弹出添加窗口
            handleCreate() {

                this.dialogFormVisible = true;

                this.formData={};

            },
            // 弹出编辑窗口
            handleUpdate(row) {

                this.dialogFormVisible=true;
                this.formData=row;

            },
            //切换页码
            handleCurrentChange(currentPage) {

                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {

                this.$confirm("是否删除", "提示").then(res => {
                    axios.post("/checkitem/delete.do?id=" + row.id).then(res => {
                        if (res.data.flag == true) {

                            this.$message({
                                type: "success",
                                message: "删除成功"
                            })
                            this.findPage();
                        } else {

                            this.$message.error(this.$message)
                        }
                    })
                })


            }
        }

    })
</script>
</html>

检查组前端:

<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预定管理<small>检查组管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预定管理</el-breadcrumb-item>
                    <el-breadcrumb-item>检查组管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="编码/名称/助记码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="code" label="检查组编码" align="center"></el-table-column>
                        <el-table-column prop="name" label="检查组名称" align="center"></el-table-column>
                        <el-table-column label="适用性别" align="center">
                            <template slot-scope="scope">
                                <span>{
  
  { scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="helpCode" label="助记码" align="center"></el-table-column>
                        <el-table-column prop="remark" label="说明" align="center"></el-table-column>
                        <el-table-column label="操做" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增检查组" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="编码">
                                                        <el-input v-model="formData.code"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="名称">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="适用性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="不限" value="0"></el-option>
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="助记码">
                                                        <el-input v-model="formData.helpCode"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="说明">
                                                        <el-input v-model="formData.remark" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="注意事项">
                                                        <el-input v-model="formData.attention" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="检查项信息" name="second">
									<div class="checkScrol">
                                        <table class="datatable">
                                            <thead>
                                            <tr>
                                                <th>选择</th>
                                                <th>项目编码</th>
                                                <th>项目名称</th>
                                                <th>项目说明</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr v-for="c in tableData">
                                                <td>
                                                    <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                                </td>
                                                <td><label :for="c.id">{
  
  {c.code}}</label></td>
                                                <td><label :for="c.id">{
  
  {c.name}}</label></td>
                                                <td><label :for="c.id">{
  
  {c.remark}}</label></td>
                                            </tr>
                                            </tbody>
                                        </table>
									</div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">肯定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="编辑检查组" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="编码">
                                                        <el-input v-model="formData.code"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="名称">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="适用性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="不限" value="0"></el-option>
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="助记码">
                                                        <el-input v-model="formData.helpCode"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="说明">
                                                        <el-input v-model="formData.remark" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="注意事项">
                                                        <el-input v-model="formData.attention" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="检查项信息" name="second">
										<div class="checkScrol">
											<table class="datatable">
												<thead>
													<tr>
														<th>选择</th>
														<th>项目编码</th>
														<th>项目名称</th>
														<th>项目说明</th>
													</tr>
												</thead>
												<tbody>
													<tr v-for="c in tableData">
														<td>
															<input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
														</td>
														<td><label :for="c.id">{
  
  {c.code}}</label></td>
														<td><label :for="c.id">{
  
  {c.name}}</label></td>
														<td><label :for="c.id">{
  
  {c.remark}}</label></td>
														<td><label :for="c.id">{
  
  {c.type}}</label></td>
													</tr>
												</tbody>
											</table>
										</div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">肯定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:10,
                    total:100,
                    queryString:null,
                },
                dataList: [],//列表数据
                formData: {},//表单数据
                tableData:[],//新增和编辑表单中对应的检查项列表数据
                checkitemIds:[],//新增和编辑表单中检查项对应的复选框,基于双向绑定能够进行回显和数据提交
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
            },
            created() {
                this.findPage();
            },
            methods: {
                //编辑
                handleEdit() {
                    // 直接发送ajax,给后台
                    axios.post("/checkgroup/update.do?ids="+this.checkitemIds,this.formData).then(res=>{
                        // if(res.data.flag == true)
                        this.dialogFormVisible4Edit = false;
                        this.findPage();
                    })
                },
                //添加
                handleAdd () {
                    // 直接发送ajax,给后台
                    axios.post("/checkgroup/add.do?ids="+this.checkitemIds,this.formData).then(res=>{
                        // if(res.data.flag == true)
                        this.dialogFormVisible = false;
                        this.findPage();
                    })

                },
                //分页查询
                findPage() {


                    axios.post("/checkgroup/findPage.do",this.pagination).then(res=>{
                        //{ total:xx,rows:[]}
                        this.dataList = res.data.rows;
                        this.pagination.total = res.data.total;
                    });
                },
                // 重置表单
                resetForm() {
                },
                // 弹出添加窗口
                handleCreate() {
                    this.dialogFormVisible = true;
                    // 查询全部检查项对象
                    axios.get("/checkitem/findAll.do").then(res=>{
                        // if(res.data.flag == true)
                        this.tableData = res.data.data;
                    })
                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    this.formData = row;
                    this.dialogFormVisible4Edit = true;

                    axios.get("/checkitem/findAll.do").then(res=>{
                        // if(res.data.flag == true)
                        this.tableData = res.data.data;

                        // 当前检查组对应,对应的检查项们的ids
                        axios.get("/checkgroup/findCheckItemIdsByGid.do?id="+row.id).then(res=>{
                            this.checkitemIds = res.data.data;
                        })
                    })

                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {

                    this.$confirm("是否删除?","提示",{type:"warning"}).then(()=>{
                        axios.get("/checkgroup/delete.do?id="+row.id).then(res=>{
                            if(res.data.flag==true){
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                this.findPage();
                            }else{
                                this.$message.error(res.data.message);
                            }
                        })
                    })
                }
            }
        })
    </script>
</html>

Controller:

检查项:


@RestController
@RequestMapping("checkitem")
public class CheckItemController {

    @Reference
    CheckItemService checkItemService;

    @RequestMapping("add")
    public Result add(@RequestBody CheckItem checkItem){
        try {
            // 添加
            checkItemService.add(checkItem);

            return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
        }catch (Exception e){
            // 打印异常
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_CHECKITEM_FAIL);
        }
    }

//修改
    @RequestMapping("update")
    public Result update(@RequestBody CheckItem checkItem){

            // 添加
            checkItemService.update(checkItem);

            return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);

    }
    //    展现全部
    @RequestMapping("findAll")
    public Result findAll(){
        List<CheckItem> all = checkItemService.findAll();
        return   new Result(true  ,MessageConstant.DELETE_CHECKITEM_SUCCESS,all);
    }
//条件查询+分页
    @RequestMapping("findPage")
    public PageResult   findPage(@RequestBody QueryPageBean queryPageBean){
        return checkItemService.findPage(queryPageBean);
    }

//删除
    @RequestMapping("delete")
    public Result   delete(Integer  id){
        List<Integer>  list=checkItemService.getie(id);
        if(list.size()>0){
       return  new Result(false,"数据有关联不能删除");
        }
        checkItemService.delete(id);
        return  new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }

}

检查组:


@RestController
@RequestMapping("checkgroup")
public class CheckGroupController {

    @Reference
    CheckGroupService checkGroupService;

    @RequestMapping("add")
    public Result add(Integer[] ids,@RequestBody CheckGroup checkGroup){
        checkGroupService.add(ids,checkGroup);
        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
    }

    @RequestMapping("update")
    public Result update(Integer[] ids,@RequestBody CheckGroup checkGroup){
        checkGroupService.update(ids,checkGroup);
        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
    }

    @RequestMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return checkGroupService.findPage(queryPageBean);
    }

    @RequestMapping("findCheckItemIdsByGid")
    public Result findCheckItemIdsByGid(Integer id){
        List<Integer> list = checkGroupService.findCheckItemIdsByGid(id);
        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS,list);

    }

    @RequestMapping("delete")
    public Result delete(Integer id){

        checkGroupService.delete(id);
        return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
    }

    @RequestMapping("findAll")
    public Result findAll(){
        List<CheckGroup> list = checkGroupService.findAll();

        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
    }

serviceImpl:

检查组:


@Service
public class CheckGroupServiceimpl  implements   CheckGroupService {

     @Autowired
    CheckGroupMapper    checkGroupMapper;

    @Override
    public void add(Integer[] ids, CheckGroup checkGroup) {
//        添加
   checkGroupMapper.add1(checkGroup);
        Integer checkGroupid = checkGroup.getId();
        for (Integer checkItemId : ids) {
//            往中间表添加
            checkGroupMapper.zhongjian(checkGroupid,checkItemId);
        }
    }

    @Override
    public void update(Integer[] ids, CheckGroup checkGroup) {
        checkGroupMapper.update(checkGroup);
        Integer checkGroupid = checkGroup.getId();



        // 将以前的关联数据所有,删除 , 在中间表删掉,根据gid
        checkGroupMapper.deleteAll(checkGroupid);
        for (Integer checkItemId : ids) {
            checkGroupMapper.zhongjian(checkGroupid,checkItemId);
        }
        }



    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<CheckGroup>  list=checkGroupMapper.findPage(queryPageBean.getQueryString());
        PageInfo<CheckGroup> p = new PageInfo<>(list);


        return   new PageResult(p.getTotal(),p.getList());
    }

    @Override
    public List<Integer> findCheckItemIdsByGid(Integer id) {
        return checkGroupMapper.findCheckItemIdsByGid(id);
    }

    @Override
    public void delete(Integer id) {
//先删除检查项  而后在删检查组
        checkGroupMapper.delete(id);
        checkGroupMapper.deleteAll(id);

    }

    @Override
    public List<CheckGroup> findAll() {
        return null;
    }

mapper   以及xml:

检查项:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.jiyun.mapper.CheckItemMapper">
    <!--插入检查项数据-->
    <insert id="add" parameterType="com.jiyun.pojo.CheckItem">
        insert into t_checkitem(code,name,sex,age,price,type,remark,attention)
                      values
        (#{code},#{name},#{sex},#{age},#{price},#{type},#{remark},#{attention})
    </insert>
    <update id="update"  parameterType="com.jiyun.pojo.CheckItem">


        update t_checkitem
        <set>
            <if test="name != null">
                name = #{name},
            </if>
            <if test="sex != null">
                sex = #{sex},
            </if>
            <if test="code != null">
                code = #{code},
            </if>
            <if test="age != null">
                age = #{age},
            </if>
            <if test="price != null">
                price = #{price},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="attention != null">
                attention = #{attention},
            </if>
            <if test="remark != null">
                remark = #{remark},
            </if>
        </set>
        where id = #{id}



    </update>
    <delete id="delete"  parameterType="int">
        delete   from  t_checkitem   where id=#{id}
    </delete>
    <select id="findPage" resultType="com.jiyun.pojo.CheckItem"  parameterType="String">
        select   *  from  t_checkitem   where 1=1
        <if test="info!=null  and info!=''">
            and name like  '%${info}%'
        </if>
    </select>
    <select id="findAll" resultType="com.jiyun.pojo.CheckItem">
                select   *  from  t_checkitem
    </select>
    <select id="getid" resultType="java.lang.Integer" parameterType="int">
        select   count(*) from  t_checkgroup_checkitem  where checkitem_id=#{id}
    </select>
</mapper>

检查组:


    <insert id="add1" parameterType="com.jiyun.pojo.CheckGroup" useGeneratedKeys="true" keyProperty="id">
              insert into t_checkgroup(code,name,sex,helpCode,remark,attention)
        values
        (#{code},#{name},#{sex},#{helpCode},#{remark},#{attention})
    </insert>
    <insert id="zhongjian"  parameterType="int">
        insert into t_checkgroup_checkitem (checkgroup_id, checkitem_id)
        values (#{gid},#{kid});
    </insert>
    <update id="update"  parameterType="com.jiyun.pojo.CheckGroup">
        update t_checkgroup
        <set>
            <if test="name != null">
                name = #{name},
            </if>
            <if test="sex != null">
                sex = #{sex},
            </if>
            <if test="code != null">
                code = #{code},
            </if>
            <if test="helpCode != null">
                helpCode = #{helpCode},
            </if>
            <if test="attention != null">
                attention = #{attention},
            </if>
            <if test="remark != null">
                remark = #{remark},
            </if>
        </set>
        where id = #{id}

    </update>
    <delete id="deleteAll"  parameterType="int">
        delete    from   t_checkgroup_checkitem   where  checkgroup_id=#{id}
    </delete>
    <delete id="delete"  parameterType="int">
                delete    from   t_checkgroup  where  id=#{id}

    </delete>
    <select id="findPage" resultType="com.jiyun.pojo.CheckGroup" parameterType="String">

        select   *  from  t_checkgroup
        <if test="info !=null and info!=''">
            where code=#{info} or name=#{info} or helpCode=#{info}
        </if>
    </select>
    <select id="findCheckItemIdsByGid" resultType="java.lang.Integer">
        select checkitem_id from t_checkgroup_checkitem
        where checkgroup_id=#{id}
    </select>

效果展现:

检查项:

展现全部:

添加:

 

 修改:

 删除:

 检查组:

展现全部:

 

添加:

 修改:

目录传送门