茂名专业网站建设公司/浏览器2345网址导航下载安装
💗wei_shuo的个人主页
💫wei_shuo的学习社区
🌐Hello World !
理清SpringBoot CURD处理逻辑、顺序
- Controller(控制器):
- 控制器接收来自客户端的请求,并负责处理请求的路由和参数解析。
- 控制器通常会调用相应的服务层方法来处理业务逻辑,并将结果返回给客户端。
- Service(服务层):
- 服务层包含了应用程序的业务逻辑。
- 服务层通常会调用数据访问对象(DAO)来进行数据的读取、写入和修改。
- 服务层可以对数据进行处理、验证和转换,并协调多个数据访问对象的操作。
- 服务层的方法可以被控制器调用,也可以被其他服务层方法调用。
- DAO(数据访问对象):
- 数据访问对象负责与数据源(如数据库)进行交互,执行数据的读取、写入和修改操作。
- DAO通常会定义一组方法,用于执行CRUD操作(创建、读取、更新、删除)。
- DAO可以使用ORM(对象关系映射)工具或手动编写SQL语句来与数据源进行交互。
- DAO的实现可以是直接操作数据库的类,也可以是使用ORM框架生成的类。
- PO(持久化对象):
- 持久化对象是与数据源中的表或集合相对应的对象。
- 持久化对象通常具有与数据表字段相对应的属性,并提供了用于读取和写入数据的方法。
- 持久化对象可以由ORM框架自动生成,也可以手动编写。
- Repo(仓库接口):
- 仓库接口定义了对领域对象的持久化和查询方法。
- 仓库接口通常包含根据特定条件查询领域对象的方法,如根据ID查询、根据条件查询等。
- 仓库接口提供了抽象的方法,用于与具体的数据访问对象进行交互。
- RepoImpl(仓库实现类):
- 仓库实现类是仓库接口的具体实现。
- 仓库实现类负责将仓库接口定义的方法与具体的数据访问对象(DAO)进行关联。
- 仓库实现类实现了仓库接口中定义的方法,并根据需要调用相应的DAO方法。
- Mapper(映射器):
- 映射器是一种用于将持久化对象与数据库表之间进行映射的工具。
- 映射器可以根据配置文件或注解来定义对象与表之间的映射关系。
- 映射器可以将持久化对象的属性映射到数据库表的列,并提供了CRUD操作的方法
联表查询接口
- Controller
@GetMapping("status")@ApiOperation("公告状态")@Logger(menu = "首页", action = "公告状态")public Result noticeStatus() {List<SystemNoticeResponse> responses = systemNoticeService.SystemNoticeStatus();return Result.succ(responses);}
- Service
/*** 公告状态** @param* @return*/public List<SystemNoticeResponse> SystemNoticeStatus() {Long merchantId = AuthContextHolder.getLoginMerchant().getId();List<SystemNoticeReaderResponse> systemNoticeReaderResponses = systemNoticeReaderRepo.SystemNoticeReaderStatus(merchantId);Map<String, Integer> idNoticeIdMap = new HashMap<>();for (SystemNoticeReaderResponse response : systemNoticeReaderResponses) {if (response.getId().equals(response.getNoticeId())) {idNoticeIdMap.put(response.getId(), 1);//已阅读:1} else {idNoticeIdMap.put(response.getId(), 0);//待阅读:0}}List<SystemNoticeResponse> noticeResponses = new ArrayList<>();for (Map.Entry<String, Integer> entry : idNoticeIdMap.entrySet()) {String id = entry.getKey();long parseLong = Long.parseLong(id);SystemNoticeResponse response = new SystemNoticeResponse(parseLong,systemNoticeRepo.getById(parseLong).getNoticeTitle(),systemNoticeRepo.getById(parseLong).getNoticeContent(),systemNoticeRepo.getById(parseLong).getCreateAt(),entry.getValue());noticeResponses.add(response);}noticeResponses = noticeResponses.stream().sorted(Comparator.comparing(SystemNoticeResponse::getReadStatus).thenComparing(Comparator.comparing(SystemNoticeResponse::getCreateAt).reversed())).collect(Collectors.toList());return noticeResponses;}
- Repo
List<SystemNoticeReaderResponse> SystemNoticeReaderStatus(Long merchantId);
- RepoImpl
@Overridepublic List<SystemNoticeReaderResponse> SystemNoticeReaderStatus(Long merchantId) {return baseMapper.systemNoticeStatus(merchantId);}
- Mapper
List<SystemNoticeReaderResponse> systemNoticeStatus(Long id);
- Mapper.xml
<select id="systemNoticeStatus" parameterType="java.lang.Long" resultMap="systemNoticeStatusResultMap">SELECT y.id, s.notice_idFROM "system_notice" as yLEFT JOIN "system_notice_reader" as s ON y."id" = s.notice_id AND s.merchant_id = #{id}</select><resultMap id="systemNoticeStatusResultMap" type="com.moozumi.bean.response.notice.SystemNoticeReaderResponse"><result column="id" property="id" /><result column="notice_id" property="NoticeId" /></resultMap>
- Dao
@Data @Builder @NoArgsConstructor @AllArgsConstructor @TableName("system_notice_reader") public class SystemNoticeReader {/*** null | system_notice_reader.id | @mbg.generated*/@ApiModelProperty("null")@TableIdprivate Long id;/*** 公告 ID | system_notice_reader.notice_id | @mbg.generated*/@ApiModelProperty("公告 ID")private Long noticeId;/*** 已阅读商户 ID | system_notice_reader.merchant_id | @mbg.generated*/@ApiModelProperty("已阅读商户 ID")private Long merchantId;}
- DaoCol:实体类字段对应的枚举类字段
public class SystemNoticeReaderCol {public static final String ID = "id";public static final String NOTICE_ID = "notice_id";public static final String MERCHANT_ID = "merchant_id";}
- DTO(VO):数据传输对象
@Data @AllArgsConstructor public class SystemNoticeReaderResponse {@ApiModelProperty("ID")private String id;@ApiModelProperty("阅读公告ID")private String NoticeId;}
@Data @AllArgsConstructor public class SystemNoticeResponse {@ApiModelProperty("id")private Long id;@ApiModelProperty("标题")private String noticeTitle;@ApiModelProperty("内容")private String noticeContent;@ApiModelProperty("创建时间")private Date createAt;@ApiModelProperty("阅读状态, 0: 待阅读, 1: 已阅读")private Integer readStatus; }
CURD接口
add
- Controller
@PostMapping("add")@ApiOperation("新增公告")@Logger(menu = "公告管理", action = "新增公告")public Result noticeAdd(@Validated @RequestBody SystemNoticeResponse insert) {systemNoticeService.addSystemNotice(insert);return Result.succ("添加成功");}
- Service
/*** 公告添加** @param insert* @return*/public SystemNotice addSystemNotice(SystemNoticeResponse insert) {SystemNotice notice = new SystemNotice(null,insert.getNoticeTitle(),insert.getNoticeContent(),new Date(),AuthContextHolder.getLoginManager().getUserRealName());systemNoticeRepo.save(notice);return notice;}
delete
- Controller
@PostMapping("delete")@ApiOperation("删除公告")@Logger(menu = "公告管理", action = "删除公告")public Result noticeDelete(@Validated @RequestBody CommonRequestId request) {systemNoticeRepo.removeById(request.getId());return Result.succ("删除成功");}
update
- Controller
@PostMapping("update")@ApiOperation("编辑公告")@Logger(menu = "公告管理", action = "编辑公告")public Result noticeUpdate(@Validated @RequestBody SystemNoticeResponse insert) {systemNoticeService.updateSystemNotice(insert);return Result.succ("更新成功");}
- Service
/*** 编辑公告** @param insert* @return*/public SystemNotice updateSystemNotice(SystemNoticeResponse insert) {SystemNotice notice = systemNoticeRepo.getById(insert.getId());if (notice != null) {notice.setNoticeTitle(insert.getNoticeTitle());notice.setNoticeContent(insert.getNoticeContent());notice.setCreateAt(new Date());systemNoticeRepo.updateById(notice);}return notice;}
list
- Controller
@GetMapping("list")@ApiOperation("展示公告")@Logger(menu = "公告管理", action = "展示公告")public Result<PageResult<SystemNotice>> list(SystemNoticeQuery query) {Page<SystemNotice> systemNoticePage = systemNoticeRepo.systemNoticeQuery(query);return Result.succ(PageResult.toPage(systemNoticePage));}
insert
- Controller
@PostMapping("insert") @ApiOperation("已阅读") @Logger(menu = "首页", action = "已阅读") public Result noticeReader(@Validated @RequestBody CommonRequestId request) {systemNoticeService.SystemNoticeReader(request.getId());return Result.succ("已阅读"); }
- Service
/*** 公告 已阅读** @param* @return*/public SystemNoticeReader SystemNoticeReader(Long noticeId) {SystemNoticeReader notice = new SystemNoticeReader(null,noticeId,AuthContextHolder.getLoginMerchant().getId());systemNoticeReaderRepo.save(notice);return notice;}
GetMapping和PostMapping辨析
- @GetMapping:用于获取(查询)资源,不应该用于修改数据(数据库获取)
- @PostMapping:用于创建资源,不应该用于查询数据(数据库编辑、修改)
Request和Response辨析
前端(客户端)—— 后端(服务器端)
- Request(请求):客户端向服务器发送的一种信息,用于请求操作或获取资源( 前端 ==》后端 )
- Response(响应):Response是服务器对客户端请求的回应,包含服务器处理结果的数据( 后端 ==》前端 )
🌼 结语:创作不易,如果觉得博主的文章赏心悦目,还请——
点赞
👍收藏
⭐️评论
📝
相关文章:

理清SpringBoot CURD处理逻辑、顺序
💗wei_shuo的个人主页 💫wei_shuo的学习社区 🌐Hello World ! 理清SpringBoot CURD处理逻辑、顺序 Controller(控制器): 控制器接收来自客户端的请求,并负责处理请求的路由和参数解析…...

缓存读写淘汰算法W-TinyLFU算法
在W-TinyLFU中,每个缓存项都会被赋予一个权重。这个权重可以表示缓存项的大小、使用频率、是否是热数据等因素。每次需要淘汰缓存时,W-TinyLFU会选择小于一定阈值的权重的缓存项进行淘汰,以避免淘汰热数据。 另外,W-TinyLFU也会根…...

C++中的 throw详解
在《C++异常处理》一节中,我们讲到了 C++ 异常处理的流程,具体为: 抛出(Throw)--> 检测(Try) --> 捕获(Catch) 异常必须显式地抛出,才能被检测和捕获到;如果没有显式的抛出,即使有异常也检测不到。在 C++ 中,我们使用 throw 关键字来显式地抛出异常,它的用…...

vue 封装Table组件
基于element-plus UI 框架封装一个table组件 在项目目录下的components新建一个Table.vue <template><section class"wrap"><el-tableref"table":data"tableData" v-loading"loading" style"width: 100%":…...

MySQL主从复制错误
当在MySQL的多线程复制中遇到错误时,你可能会看到上述的错误信息。错误的核心在于从服务器上的工作线程在尝试执行一个特定的事务时遇到了问题。 为了解决这个问题,你可以采取以下步骤: 查看MySQL的错误日志:错误日志可能会提供更…...

Redis群集
目录 1、redis群集三种模式 2、Redis 主从复制 2.1 主从复制的作用 2.2 主从复制流程 2.3 搭建Redis 主从复制 3、Redis 哨兵模式 3.1 哨兵模式的作用 3.2 故障转移机制 3.3 主节点的选举 4、Redis 群集模式 4.1 集群的作用 4.2 Redis集群的数据分片 4.3 搭建Redis…...

Spring AOP以及统一处理
一.Spring AOP 1.什么是Spring AOP AOP(Aspect Oriented Programming):面向切面编程,它是一种思想,它是对某一类事情的集中处理。 2.AOP的作用 想象一个场景,我们在做后台系统时,除了登录…...

vue2markdown转思维导图
官网 http://markmap.js.org 按照官网安装markmap-lib,markmap-view两个依赖外,还需要安装markmap-common 如果报错提示vuePdfNoSss相关问题,需要安装vue-pdf 如果报错can’t import the named export ‘xxx’ from non EcmaScript module,需…...

docker下redis备份文件dump.rdb获取
1.查看镜像 docker ps -a 2.进入redis客户端 docker exec -it redis redis-cli 3.保存备份文件 save 4.查看文件存放位置 CONFIG GET dir 5.将docker中文件拷出 docker cp id或name:容器中文件的路径 目标目录地址...

二十一、MySQL(多表)内连接、外连接、自连接实现
1、多表查询 (1)基础概念: (2)多表查询的分类: 2、内连接 (1)基础概念: (2)隐式内连接: 基础语法: select 表1.name,…...

Zookeeper运维
我是一个目录 1. 参数说明2. Zookeeper优化建议3. Zookeeper性能查看4. 建议 1. 参数说明 工作节点瞬间压力大,导致和集群通信出现延迟,被踢出节点,瞬间释放的连接立即又连接到另外节点,最终集群挂掉。加了一些延迟配置后…...

uniapp 点击事件-防重复点击
uniapp 点击事件-防重复点击 1、common文件并创建anti-shake.js文件 // 防止处理多次点击 function noMoreClicks(methods, info) {// methods是需要点击后需要执行的函数, info是点击需要传的参数let that this;if (that.noClick) {// 第一次点击that.noClick f…...

推进“数智+数治”,中期科技智慧公厕驱动城市公厕更新升级发展
随着城市化的快速发展和人口的不断增加,公共厕所这一基础设施的更新升级成为了亟待解决的问题。过去的传统公厕往往存在着环境脏乱差、无法保证使用者的舒适度等诸多问题。而智慧公厕则能够通过互联网和物联网的技术手段,实现智能化的运行管理࿰…...

4、模板(二叉树,红黑树,STL的实现)
1. 泛型编程 2. 模板:参数类型化 3. 模板分类 3.1 函数模板 概念 实例化:隐式实例化,显式实例化 3.2 类模板 4. 在模板参数列表中:class和typename 5.模板参数列表:template <class T , size_t N> 类型参数&#x…...

了解JVM
一.了解JVM 1.1什么是JVM JVM是Java Virtual Machine(Java虚拟机)的缩写,是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟计算机功能来实现的,JVM屏蔽了与具体操作系统平台相关的信息,Java程序只…...

vue2实现组织机构树
参考大佬文章:https://www.cnblogs.com/10ve/p/12573772.html 【vue——实现组织架构图(vue-org-tree)——技能提升 - CSDN App】http://t.csdn.cn/Mpe4B...

JS中BigInt的使用
JS中BigInt的使用 BigInt是一种内置对象,它提供了一种方法来表示大于2^53 - 1的整数,通俗来讲就是提供了一种可以表示任意大整数的方法,当我们使用Number来表示一个超过了2 ^53 - 1的整数的时候,会出错。所以此时我们需要使用Big…...

你的第1个 Unity 游戏!!!
简介 首先新建一个方块添加重力!!!总结首先 首先,你要先打开 U n i t y Unity Unity...

炫云云渲染3ds max效果图渲染教程
很多人在第一次使用炫云云渲染渲染效果图的时候不知道怎么使用,其实现在使用炫云渲染效果图真的很简单,我们一起来看看。 一客户端安装 1、打开炫云云渲染官网,点击右上角的客户端下载,选择炫云客户端(NEXT版…...

Java中数组array和列表list相互转换
在Java中,可以将数组(array)和列表(list)相互转换,但需要注意一些细节和限制。以下是一些示例和说明: 从数组到列表: 使用Arrays.asList()方法:可以使用Arrays.asList()…...

【JavaSE笔记】数据类型与变量
一、前言 在Java这门“啰嗦”的编程语言中,我们必须弄清楚每种数据类型的性质和用途,才能让程序“说人话”。要成为Java高手,就必须与各种数据类型打成一片。 本文则将带你认识Java中常见的两位“角色”—数据类型与变量。 二、数据类型 在Java中数据类型主要分…...

VR全景智慧文旅解决方案,助力文旅产业转型升级
引言: 随着科技的不断发展,虚拟现实(VR)技术正逐渐展露其影响力,改变着旅游业。VR全景智慧文旅解决方案也应运而生,将传统旅游的体验形式从线下扩展到了线上,带来了不一般的文旅体验。 一.VR全…...

采用cv2和默认的人脸识别分类器实现人脸检测功能
人脸识别分类器 haarcascade_frontalface_default 提示:分类器文件地址在这里:https://github.com/opencv/opencv/blob/687fc11626901cff09d2b3b5f331fd59190ad4c7/data/haarcascades/haarcascade_frontalface_default.xml 文章目录 人脸识别分类器 haar…...

C# 实现迷宫游戏
智能提示: /// <summary>/// 迷宫/// </summary>internal class Maze : IDisposable{private MazeCell[,] cells;private readonly Stack<MazeCell> stack new Stack<MazeCell>();private readonly Random rand new Random();private int…...

chales 重写/断点/映射/手机代理/其他主机代理
1 chales 安装和代理配置/手机代理配置/电脑代理配置 chales 安装和代理配置/手机代理配置/电脑代理配置 2 转载:Charles Rewrite重写(详解!必懂系列) Charles Rewrite重写(详解!必懂系列) 1.打开charles,点击菜单栏的Tools选中Rewrite2.…...

django添加数据库字段进行数据迁移
1.修改view.py里面的变量 2.在model.py新增字段 3.打开terminal并将环境切到项目所在环境,切换方式为 4.执行命令 python manage.py makemigrations backend python manage.py migrate...

flink1.15.0消费kafka 报错 The coordinator is not available.
报错 You should retry committing the latest consumed offsets. Caused by: org.apache.kafka.common.errors.CoordinatorNotAvailableException: The coordinator is not available. 但是任务还在正常跑. 开源bug [FLINK-28060] Kafka Commit on checkpointing fails re…...

2023华为杯研究生数学建模F题思路模型代码(9.22早第一时间更新)
目录 1.F题思路模型:9.7晚上比赛开始后,第一时间更新,获取见文末名片 3 全国大学生数学建模竞赛常见数模问题常见模型分类 3.1 分类问题 3.2 优化问题 详细思路见此名片,开赛第一时间更新 1.F题思路模型:9.7晚上比…...

[k8s] pod的创建过程
pod的创建过程 定义 Pod 的规范: apiVersion: v1 kind: Pod metadata:name: my-pod spec:containers:- name: my-containerimage: nginx:latest创建 Pod 对象: 使用 kubectl 命令行工具或其他客户端工具创建 Pod 对象: kubectl create -f…...

[网鼎杯 2020 朱雀组]phpweb call_user_func()
时间一跳一跳的 抓个包 很奇怪 结合上面的 date() 认为第一个是函数 我们随便输一个看看 发现过滤了 随便输一个 linux指令 发现报错了 call_user_func() 看看是啥 很容易理解 第一个参数是函数名 后面是 参数 那么这里就是 func 函数 p 数值 所以我们看看有什么办法可以…...