粤嵌实训医疗项目--day04(Vue + SpringBoot)

 往期回顾

  • 粤嵌实训医疗项目--day03(Vue + SpringBoot)-CSDN博客
  • 粤嵌实训医疗项目day02(Vue + SpringBoot)-CSDN博客
  • 粤嵌实训医疗项目--day01(Vue+SpringBoot)-CSDN博客

目录

一、用户详细信息查询 (查询信息与分页显示)

二、实现信息修改功能(增添、编辑、删除)


 

一、用户详细信息查询 (查询信息与分页显示)

--前端中创建view包,并在view包下创建对应用户查询信息的页面

UserInfoList页面布局前端代码

<template>
    <div>
        <div style="margin: 20px 0px;">
            <!-- input -->
            <el-input placeholder="请输入内容" v-model="keyword" clearable style="width: 20%;"> </el-input>
            <!-- 模糊搜索功能 -->
            <el-button type="primary" @click="query">搜索</el-button>

            <!-- 新增功能 -->
            <el-button type="success" @click="dialogVisible = true">新增</el-button>
            <el-dialog title="新增/编辑" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="姓名">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号码">
                        <el-input v-model="form.phone"></el-input>
                    </el-form-item>
                    <el-form-item label="头像">
                        <!-- action表示为上传文件的url   -->
                        <el-upload class="avatar-uploader" action="http://localhost:8085/file/upload/"
                            :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
                            <img v-if="imageUrl" :src="imageUrl" class="avatar" />
                            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                        </el-upload>
                    </el-form-item>
                    <el-form-item label="密码">
                        <el-input v-model="form.password"></el-input>
                    </el-form-item>
                    <el-form-item label="角色">
                        <el-select v-model="form.role" placeholder="请选择" style="width: 100%">
                            <el-option v-for="item in options" :key="item.role" :label="item.label" :value="item.role">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="身份证号">
                        <el-input v-model="form.code"></el-input>
                    </el-form-item>
                    <el-form-item label="邮箱">
                        <el-input v-model="form.email"></el-input>
                    </el-form-item>
                    <el-form-item label="性别" prop="registrsex">
                        <el-radio v-model="form.sex" label="男">男</el-radio>
                        <el-radio v-model="form.sex" label="女">女</el-radio>
                    </el-form-item>
                    <el-form-item label="年龄">
                        <el-input v-model="form.age"></el-input>
                    </el-form-item>
                    <el-form-item label="职业">
                        <el-input v-model="form.job"></el-input>
                    </el-form-item>

                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="handleCloseAfter">取 消</el-button>
                    <el-button type="primary" @click="save">确 定</el-button>
                </div>
            </el-dialog>
        </div>

        <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="userId" label="id"> </el-table-column>
            <el-table-column prop="userName" label="姓名"> </el-table-column>
            <el-table-column prop="code" label="身份证号"> </el-table-column>
            <el-table-column prop="email" label="邮箱"> </el-table-column>
            <el-table-column prop="sex" label="性别"> </el-table-column>
            <el-table-column prop="age" label="年龄"> </el-table-column>
            <el-table-column prop="job" label="职业"> </el-table-column>
            <el-table-column prop="status" label="通行码">
                <!-- scope表示为作用域  scope.row表示为作用域中这一行的数据 -->
                <template slot-scope="scope">
                    <el-button size="small" @click="showStauts(scope.row.userId)" type="success"
                        v-if="scope.row.status == 0">绿码</el-button>
                    <el-button size="small" @click="showStauts(scope.row.userId)" type="warning"
                        v-if="scope.row.status == 1">黄码</el-button>
                    <el-button size="small" @click="showStauts(scope.row.userId)" type="danger"
                        v-if="scope.row.status == 2">红码</el-button>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="150">
                <template slot-scope="scope">
                    <el-button size="mini" native-type @click="handleEdit(scope.row)">编辑</el-button>
                    <el-button size="mini" native-type type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 定义一个分页标签 -->
        <div>
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum"
                :page-sizes="[3, 8, 15, 30]" :page-size="3" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
        <!-- 定义一个对话框 -->
        <div>
            <el-dialog title="用户的通行码" :visible.sync="dialogQrCodeVisible" width="30%" :before-close="handleQrCodeClose">
                <img :src="QrCode" />
            </el-dialog>
        </div>

    </div>
</template>

<script>
//导入request工具
import request from "@/utils/request";


export default {
    //data表示vue对象中存储的数据
    data() {
        return {
            dialogVisible: false,
            dialogQrCodeVisible: false,
            QrCode: '',
            tableData: [],
            pageNum: 1,
            pageSize: 3,
            total: 0,
            keyword: "",
            imageUrl: '',
            form: {
                userId: '',
                name: '',
                phone: '',
                image: '',
                password: '',
                role: '',
                code: '',
                email: '',
                sex: '',
                age: '',
                job: '',
                status: '',
            },
            options: [
                {
                    role: 1,
                    label: '用户'
                }, {
                    role: 2,
                    label: '医护'
                },
            ],
            formLabelWidth: '120px',


        };
    },
    //created页面加载完触发的生命周期
    created() {
        this.query();

    },


    methods: {


        //成功后的处理函数
        handleAvatarSuccess(res, file) {
            console.log("file===" + file);
            this.imageUrl = URL.createObjectURL(file.raw);
            this.form.image = res;
        },
        //上传之前的处理函数
        beforeAvatarUpload(file) {
            const isJPG = file.type === "image/jpeg";
            const isPNG = file.type === "image/png";
            const isLt2M = file.size / 1024 / 1024 < 2;
            if (!isJPG) {
                this.$message.error("上传头像图片只能是 JPG 格式!");
            }
            if (!isLt2M) {
                this.$message.error("上传头像图片大小不能超过 2MB!");
            }
            console.log("isJPG===" + ((isJPG || isPNG) && isLt2M));
            return (isJPG || isPNG) && isLt2M;
        },
        // 重载方法
        query() {
            //发起一个异步请求,查询分类的数据
            request
                // get表示指定请求地址 和 请求参数
                .get("/gec/user-info/list", {
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        keyWord: this.keyword,
                    },
                })
                // then表示请求后的回调函数
                .then((res) => {
                    console.log(res);
                    // 把后台的响应的数据赋值给data中的tableData
                    this.tableData = res.list;
                    this.total = res.total;
                });
        },
        //二维码对话框
        showStauts(id) {
            //1、发起二维码的请求
            this.QrCode = "http://localhost:8085/code?id=" + id;
            //2、显示对话框
            this.dialogQrCodeVisible = true;
        },
        handleQrCodeClose() {
            this.dialogQrCodeVisible = false;
            this.QrCode = '';
        },

        //修改/新增对话框
        handleClose() {
            this.$confirm('是否退出?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.dialogVisible = false;
                this.form = {
                    userId: '',
                    name: '',
                    phone: '',
                    image: '',
                    password: '',
                    role: '',
                    code: '',
                    email: '',
                    sex: '',
                    age: '',
                    job: '',
                    status: '',
                };
                this.imageUrl = "";
            }).catch(() => { }
            );
        },

        handleCloseAfter() {
            this.form = {
                userId: '',
                name: '',
                phone: '',
                image: '',
                password: '',
                role: '',
                code: '',
                email: '',
                sex: '',
                age: '',
                job: '',
                status: '',
            };
            this.imageUrl = "";
            this.dialogVisible = false;
        },


        save() {
            console.log(this.form);

            if (this.form.userId == "") {

                request
                    .post("/gec/user-info/insert", this.form)
                    .then((res) => {
                        if (res.ok == true) {
                            this.$message({
                                type: 'success',
                                message: '新增成功!'
                            });
                            this.dialogVisible = false;
                            this.form = {
                                userId: '',
                                name: '',
                                name: '',
                                phone: '',
                                image: '',
                                password: '',
                                role: '',
                                code: '',
                                email: '',
                                sex: '',
                                age: '',
                                job: '',
                                status: '',
                            };
                            this.imageUrl = "";
                            this.query();
                        } else {
                            this.$message({
                                type: 'error',
                                message: '新增失败!'
                            });
                        }
                    });
            } else {
                request
                    .post("/gec/user-info/update", this.form)
                    .then((res) => {
                        console.log(this.form);

                        if (res.ok == true) {
                            this.$message({
                                type: 'success',
                                message: '修改成功!'
                            });
                            this.dialogVisible = false;
                            this.form = {
                                userId: '',
                                name: '',
                                phone: '',
                                image: '',
                                password: '',
                                role: '',
                                code: '',
                                email: '',
                                sex: '',
                                age: '',
                                job: '',
                                status: '',

                            };
                            this.query();
                        } else {
                            this.$message({
                                type: 'error',
                                message: '修改失败!'
                            });
                        }
                    }).catch((res) => {

                        console.log(res.ok);
                    });


            }

        },

        handleEdit(row) {
            console.log(row);
            this.dialogVisible = true;
            this.form.userId = row.userId;
            this.imageUrl = row.user.image;
            this.form.id = row.userId;
            this.form.name = row.userName;
            this.form.phone = row.user.phone;
            this.form.image = row.user.image;
            this.form.password = row.user.password;
            this.form.role = row.user.role;
            this.form.email = row.email;
            this.form.code = row.code;
            this.form.name = row.user.name;
            this.form.sex = row.sex;
            this.form.age = row.age;
            this.form.job = row.job;
            this.form.status = row.status;

            // this.form = row;
        },

        //删除方法
        handleDelete(index, row) {

            this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                //删除操作
                request
                    .get("/gec/user-info/delete", {
                        params: {
                            id: row.userId
                        },
                    })
                    .then((res) => {
                        if (res.ok == true) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.query();
                        } else {
                            this.$message({
                                type: 'error',
                                message: '删除失败!'
                            });
                        }
                    });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },

        //修改单页数据数量
        handleSizeChange(val) {
            this.pageNum = 1;
            this.pageSize = val;
            this.query();
        },
        //跳转页码
        handleCurrentChange(val) {
            console.log(val);
            this.pageNum = val;
            this.query();
        }



    },
};
</script>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409eff;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}

.avatar {
    width: 178px;
    height: 178px;
    display: block;
}

.el-date-editor.el-input,
.el-date-editor.el-input__inner {
    width: 335px;
}
</style>

--在前端项目中的Aside.vue进行如下修改

--在路由中添加UserInfoList的访问地址

 --在userinfo实体类中提供username

--在userinfoController中提供查询接口

@RestController
@RequestMapping("/gec/user-info")
public class UserInfoController {

    @Autowired   //注入到容器中
    UserInfoService userInfoService;

    @Autowired
    IUserService userService;
    //json 的解析工具
    ObjectMapper jsonTool = new ObjectMapper();
    @RequestMapping("/list")                                                     //页码
    public String list(@RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize,
                       @RequestParam("keyWord") String keyword) throws JsonProcessingException {
        //        1.创建json解析工具
        ObjectMapper json = new ObjectMapper();
        //       2.返回的结果集
        HashMap map = new HashMap<>();
//        提供条件构造器
        QueryWrapper<UserInfo> wrapper = new QueryWrapper<>();
//        用什么可以作为查询条件 使用身份证作为查询条件
        wrapper.like("code", keyword);
//        分页工具类
        Page<UserInfo> page = new Page<>(pageNum, pageSize);
//        进行分页后的数据
        page = userInfoService.page(page,wrapper);
//         从page中获取分页额度数据
        List<UserInfo> infoList = page.getRecords();
//        遍历数据 类型      引用名称  需要遍历的数据
        for (UserInfo userInfo : infoList) {
//               根据 userinfo 查询 user的数据
            User user = userService.getById(userInfo.getUserId());
//               把user对象的name属性 赋值给 userinfo 的userName
            userInfo.setUserName(user.getName());
        }
//           把数据保存到map 传递给前端
        map.put("total", page.getTotal());
        map.put("list", infoList);


        return jsonTool.writeValueAsString(map);
    }
}

 实现分页功能,还需要在后端项目的config包下创建pageConfig类,并添加以下代码

package com.example.vaccinum.config;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PageConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

功能展示:
1.用户信息功能展示

2.页码分页功能展示


二、实现信息修改功能(增添、编辑、删除)

添加修改功能一起实现

 @RequestMapping("/update")
    public String update(User user, UserInfo userInfo) throws JsonProcessingException {
        //       1.返回的结果集
        HashMap map = new HashMap<>();
//        isEmpty判断为null
        if (ObjectUtils.isEmpty(user.getId())) {
            //            添加
            user.setCodeid(userInfo.getCode());
            boolean save = userService.saveOrUpdate(user);


            userInfo.setUserId(user.getId());
            boolean save1 = userInfoService.save(userInfo);
            map.put("ok", save1 && save);
            map.put("message","添加成功");

        } else {
//            修改
            boolean b = userService.saveOrUpdate(user);
            boolean b1 = userInfoService.saveOrUpdate(userInfo);
            map.put("ok", b && b1);
            map.put("message","修改成功");
        }

        return jsonTool.writeValueAsString(map);
    }

在list方法中添加

新增方法接口名称修改

实现删除功能

前端对应实现方法

//删除方法
        handleDelete(index, row) {

            this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                //删除操作
                request
                    .get("/gec/user-info/delete", {
                        params: {
                            id: row.userId
                        },
                    })
                    .then((res) => {
                        if (res.ok == true) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.query();
                        } else {
                            this.$message({
                                type: 'error',
                                message: '删除失败!'
                            });
                        }
                    });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },

可以看到前端是通过参数id实现删除即根据id删除,所以对应的接口如下

  @RequestMapping("/delete")
    public String delete(Integer id) throws JsonProcessingException {
        HashMap map = new HashMap<>();
        boolean save = service.removeById(id);
        boolean save1 = userInfoService.removeById(id);

        map.put("ok",save1&&save);

        return JsonTool.writeValueAsString(map);
    }

 功能展示

1.增加用户

添加后效果如下

2.编辑用户

效果如下

3.删除用户

效果如下


 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/108829.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Java 进阶篇】使用 Java 和 Jsoup 进行 XML 处理

XML&#xff08;可扩展标记语言&#xff09;是一种常用的数据交换格式&#xff0c;它被广泛用于在不同系统之间传递和存储数据。Java作为一种强大的编程语言&#xff0c;提供了多种方式来处理XML数据。其中&#xff0c;Jsoup 是一个流行的Java库&#xff0c;用于解析和操作XML文…

vue3后台管理系统之跨域代理

vite.config.js中 server: {port: 5002,host: true, //0.0.0.0open: false,strictPort: true,proxy: {// 请求前缀/api&#xff0c;只有加了/api前缀的请求才会走代理(前端自定义)/api: {target: http://127.0.0.1:8000,// 获取服务器地址的设置changeOrigin: true,// 路径重写…

H5游戏源码分享-考眼力游戏猜猜金币在哪

H5游戏源码分享-考眼力游戏猜猜金币在哪 <!DOCTYPE html> <html> <head><meta http-equiv"Content-Type" content"text/html; charsetUTF-8"><meta charset"UTF-8"><meta name"apple-mobile-web-app-capa…

国家网信办发布第十三批境内区块链信息服务备案编号

2019年2月15日《区块链信息服务管理规定》&#xff08;以下简称《管理规定》&#xff09;正式实施以来&#xff0c;国家互联网信息办公室依法依规组织开展备案审核工作&#xff0c;已发布2批次共506个境内区块链信息服务名称及备案编号&#xff0c;近日正式发布第三批共224个境…

若依ruoyi-nbcio如何做一个仿钉钉流程设计器的思考

更多ruoyi-nbcio功能请看演示系统 gitee源代码地址 前后端代码&#xff1a; https://gitee.com/nbacheng/ruoyi-nbcio 演示地址&#xff1a;RuoYi-Nbcio后台管理系统 看到有些流程图采用仿钉钉的流程设计&#xff0c;比如下面界面&#xff1a; 这种方式虽然简单&#xff0c…

shell中的运算

目录 1.运算符号 2.运算指令 练习 1.运算符号 运算符号意义加法-减法*乘法/除法%除法后的余数**乘方自加一- -自减一<小于<小于等于>大于>大于等于等于ji ->jji*j*i->jj*i/j/i->jj/i%j%i->jj%i 2.运算指令 (()) //((a12))let //let a12 …

Starknet开发工具

1. 引言 目前Starknet的开发工具流可为&#xff1a; 1&#xff09;Starkli&#xff1a;音为Stark-lie&#xff0c;为替换官方starknet-CLI的快速命令行接口。Starkli为单独的接口&#xff0c;可独自应用&#xff0c;而不是其它工具的组件。若只是想与Starknet交互&#xff0…

《算法通关村—最大小栈问题解析》

《算法通关村—最大小栈问题解析》 最小栈 描述 leetCode 155: 设计一个支持 push &#xff0c;pop &#xff0c;top 操作&#xff0c;并能在常数时间内检索到最小元素的栈。 实现最小栈 MinStack() 初始化堆栈对象。 void push(int val) 将元素val推入堆栈。 void pop()…

MVC架构_Qt自己的MV架构

文章目录 前言模型/视图编程1.先写模型2. 视图3. 委托 例子&#xff08;Qt代码&#xff09;例1 查询本机文件系统例2 标准模型项操作例3 自定义模型示例:军事武器模型例4 只读模型操作示例例5 选择模型操作例6 自 定 义委 托(在testSelectionModel上修改) 前言 在Qt中&#xf…

YouTube博主数据信息资源

YouTube博主数据信息资源 &#x1f525;我是一位拥有10年编程经验的程序猿&#xff0c;为你带来一个全新的优质资源 &#x1f50d;您是否在寻找最新、最活跃的YouTube博主数据&#xff0c;以助力你的项目、营销或研究&#xff1f; 我们的数据&#xff0c;您的优势&#xff1a;…

Azure - 机器学习实战:快速训练、部署模型

本文将指导你探索 Azure 机器学习服务的主要功能。在这里&#xff0c;你将学习如何创建、注册并发布模型。此教程旨在让你深入了解 Azure 机器学习的基础知识和常用操作。 关注TechLead&#xff0c;分享AI全维度知识。作者拥有10年互联网服务架构、AI产品研发经验、团队管理经验…

97. 交错字符串

题目链接&#xff1a;力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 解题思路&#xff1a;动态规划。 如果s1.length()s2.length ! s3.length()&#xff0c;直接返回false&#xff0c;否则使用动态规划求解。定义状态&#xff1a;dp[i][i]&#xff…

STM32F10xx 存储器和总线架构

一、系统架构 在小容量、中容量和大容量产品 中&#xff0c;主系统由以下部分构成&#xff1a; 四个驱动单元 &#xff1a; Cotex-M3内核、DCode总线&#xff08;D-bus&#xff09;和系统总线&#xff08;S-bus&#xff09; 通用DMA1和通用DMA2 四个被动单元 内部SRAM 内部…

TeeChart for .NET 2023.10.19 Crack

TeeChart.NET 的 TeeChart 图表控件提供了一个出色的通用组件套件&#xff0c;可满足无数的图表需求&#xff0c;也针对重要的垂直领域&#xff0c;例如金融、科学和统计领域。 数据可视化 数十种完全可定制的交互式图表类型、地图和仪表指示器&#xff0c;以及完整的功能集&am…

Linux之系统编程

1.yum 1.yum list可以出现所有可下载的程序 辅助grep进行查找 2.yum install可以下载并安装 3.yum remove可以卸载程序 不同的商业操作系统内核都是一样的&#xff0c;主要是配套社区不一样。 开源组织&#xff0c;各大公司&#xff0c;既得利益者。 同上 基础软件源可以保证…

软考高级系统架构 上午真题错题总结

目录 前言一、2022年真题&#xff08;√&#xff09;二、2021年真题&#xff08;√&#xff09;三、2020年真题&#xff08;√&#xff09;四、2019年真题&#xff08;√&#xff09;五、2018年真题&#xff08;√&#xff09;六、2017年真题&#xff08;√&#xff09;七、201…

[Python]unittest-单元测试

目录 unittest的大致构成: Test Fixture Test Case-测试用例 Test Suite-测试套件 Test Runner 批量执行脚本 makeSuite() TestLoader discover() 用例的执行顺序 忽略用例执行 skip skipIf skipUnless 断言 HTML测试报告 错误截图 unittest是python中的单元测…

《红蓝攻防对抗实战》八.利用OpenSSL对反弹shell流量进行加密

前文推荐&#xff1a; 《红蓝攻防对抗实战》一. 隧道穿透技术详解《红蓝攻防对抗实战》二.内网探测协议出网之TCP/UDP协议探测出网《红蓝攻防对抗实战》三.内网探测协议出网之HTTP/HTTPS协议探测出网《红蓝攻防对抗实战》四.内网探测协议出网之ICMP协议探测出网《红蓝攻防对抗…

【C++深入浅出】模版初识

目录 一. 前言 二. 泛型编程 三. 函数模版 3.1 函数模版的概念 3.2 函数模版的格式 3.3 函数模版的原理 3.4 函数模板的实例化 3.5 模板参数的匹配原则 四. 类模版 4.1 类模版的定义 4.2 类模版的实例化 一. 前言 本期我们要介绍的是C的又一大重要功能----模版。通…

单例模式详解【2023年最新】

一、单例模式概念 单例模式是一种创建型设计模式&#xff0c;它确保一个类只有一个实例&#xff0c;并提供一个全局访问点来访问该实例。它的目的是限制一个类只能创建一个对象&#xff0c;以确保在整个应用程序中只有一个共享的实例。 单例模式通常用于以下情况&#xff1a;…
最新文章