网站开发php工程师/郑州网站建设用户

网站开发php工程师,郑州网站建设用户,网站的开发工具有哪些,网站开发面试题基于SpringBoot和MybatisPlus实现通用Controller,只需要创建实体类和mapper接口,单表增删改查接口就已经实现,提升开发效率 1.定义通用controller package com.xian.controller;import cn.hutool.core.map.MapUtil; import com.baomidou.my…

基于SpringBoot和MybatisPlus实现通用Controller,只需要创建实体类和mapper接口,单表增删改查接口就已经实现,提升开发效率

1.定义通用controller

package com.xian.controller;import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xian.common.alias.*;
import com.xian.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;@RestController
@RequestMapping("/api/v1/data")
public class BaseController<T extends Serializable> {@Autowiredprivate ApplicationContext applicationContext;private T entity;// 使用泛型和IService来处理通用CRUD操作protected <S extends BaseMapper<T>> S getMapper(String entityName) throws Exception {String serviceName = entityName + "Mapper"; // 假设服务名与实体名相同return (S) applicationContext.getBean(serviceName);}@GetMapping("/{entityName}/get/{id}")public Result get(@PathVariable String entityName, @PathVariable Long id) throws Exception {BaseMapper<T> mapper = getMapper(entityName);return Result.success(mapper.selectById(id));}@GetMapping("/{entityName}/all")public Result get(@PathVariable String entityName) throws Exception {BaseMapper<T> mapper = getMapper(entityName);return Result.success(mapper.selectList(new QueryWrapper<>()));}@PostMapping("/{entityName}/insert")public Result insert(@PathVariable String entityName,@RequestBody T entity) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);ValidateService<T> validateService = new ValidateServiceImpl<>();validateService.validate(entity,baseMapper);baseMapper.insert(entity);return Result.success();}@PutMapping("/{entityName}/update")public Result update(@PathVariable String entityName,@RequestBody T entity) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);// 使用Spring注入验证服务// 验证数据ValidateService<T> validateService = new ValidateServiceImpl<>();validateService.validate(entity, baseMapper);baseMapper.updateById(entity);return Result.success();}@PutMapping("/{entityName}/delete/{id}")public Result update(@PathVariable String entityName,@PathVariable Long id) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);baseMapper.deleteById(id);return Result.success();}@PutMapping("/{entityName}/deleteByIds")public Result update(@PathVariable String entityName,@RequestBody Collection<Long> ids) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);baseMapper.deleteBatchIds(ids);return Result.success();}// 可以添加其他通用的增删改查方法...@PostMapping("/{entityName}/list")public Result update(@PathVariable String entityName, @RequestBody PageRequestVo pageRequest) throws Exception {BaseMapper<T> baseMapper =  getMapper(entityName);System.out.println("pageRequest = " + pageRequest);PageHelper.startPage(pageRequest.getPage(), pageRequest.getSize());QueryWrapper<T> queryWrapper = new QueryWrapper<>();List<String> sort = pageRequest.getSorts();if (sort!=null&& !sort.isEmpty()) {sort.forEach(o -> {if (o.endsWith("Asc")) {queryWrapper.orderByAsc(o.replace("Asc", ""));}else if (o.endsWith("Desc")) {queryWrapper.orderByDesc(o.replace("Desc", ""));}else {queryWrapper.orderByAsc(o);}});}if (!MapUtil.isEmpty(pageRequest.getParams())){// 处理查询参数pageRequest.getParams().forEach((field, values) -> {if (values != null && !values.isEmpty()) {if (field.endsWith("Like")) {for (Object value : values) {queryWrapper.like(field.replace("Like",""), value);}}else if (field.endsWith("Is")){for (Object value : values) {queryWrapper.eq(field.replace("Like",""), value);}}else if (field.endsWith("Between")){queryWrapper.between(field.replace("Between",""), values.get(0), values.get(1));}else if (field.endsWith("IsNull")){queryWrapper.isNull(field.replace("IsNull",""));}else if (field.endsWith("IsNotNull")){queryWrapper.isNotNull(field.replace("IsNotNull",""));}else if (field.endsWith("NotIn")){queryWrapper.notIn(field.replace("NotIn",""), values);}else if (field.endsWith("In")){queryWrapper.in(field.replace("In",""), values);}else if (field.endsWith("Gt")){queryWrapper.gt(field.replace("Gt",""), values.get(0));}else if (field.endsWith("Ge")){queryWrapper.ge(field.replace("Ge",""), values.get(0));}else if (field.endsWith("Lt")){queryWrapper.lt(field.replace("Lt",""), values.get(0));}else if (field.endsWith("Le")){queryWrapper.le(field.replace("Le",""), values.get(0));}else if (field.endsWith("Eq")){for (Object value : values) {queryWrapper.eq(field.replace("Eq",""), value);}}else if (field.endsWith("Ne")){queryWrapper.ne(field.replace("Ne",""), values.get(0));}else if (field.endsWith("NotBetween")){queryWrapper.notBetween(field.replace("NotBetween",""), values.get(0), values.get(1));}else {for (Object value : values) {queryWrapper.eq(field, value);}}}});}return Result.success(PageInfo.of(baseMapper.selectList(queryWrapper)));}}

2.创建业务实体和mapper接口,

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class User extends Account {@TableId(type = IdType.AUTO)private Integer id;private String username;private String password;private String name;private String avatar;private String role;private String sex;private String phone;private String email;private String info;private String birth;@TableField(exist = false)private Integer blogCount;@TableField(exist = false)private Integer likesCount;@TableField(exist = false)private Integer collectCount;}

mapper接口:

@Mapper
public interface UserMapper extends BaseMapper<User> {
}

postman测试

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Axure大屏可视化原型模板及素材:数据可视化的高效解决方案

数据可视化已成为企业决策、运营分析、市场洞察的重要工具。数据可视化大屏&#xff0c;作为数据展示和交互的直观平台&#xff0c;能够实时呈现关键数据&#xff0c;帮助企业快速做出决策。Axure作为原型设计领域的领先工具&#xff0c;以其丰富的组件库、强大的交互设计能力和…

YOLOE:实时查看任何事物

摘要 https://arxiv.org/pdf/2503.07465v1 目标检测和分割在计算机视觉应用中得到了广泛应用&#xff0c;然而&#xff0c;尽管YOLO系列等传统模型高效且准确&#xff0c;但它们受限于预定义的类别&#xff0c;阻碍了在开放场景中的适应性。最近的开放集方法利用文本提示、视觉…

這是我第一次寫關於aapenal服務器管理控制面板的文章

首先我們來認識一下服務器管理面板的所有功能  網站管理功能&#xff1a; 支持創建和管理多個網站。配置虛擬主機&#xff08;Vhost&#xff09;和域名綁定。自動安裝常用應用&#xff08;如WordPress、Joomla等&#xff09;。  文件管理功能&#xff1a; 文件上傳、…

jmeter:登录接口的token用于下一个接口

问题&#xff1a; 仅仅登录接口可以使用&#xff0c;其他接口进行测试的时候都是报错&#xff1a;账号已经失效 原因&#xff1a; 应该是登录接口的token并没有用到下一个接口上来 解决方法 1、目录建设如下&#xff1a; 2、先添加一个后置处理器&#xff1a;查看结果数&…

1、操作系统引论

一、操作系统 会使用linux系统 建议大家先学会linux的基础指令&#xff0c;可以看菜鸟教程网站进行学习。 1、各种定义 操作系统定义 管理计算机的 硬件 和软件资源&#xff0c; 能对各类作业进行调度&#xff0c;方便用户使用计算机的程序集合。操作系统运行在内核态&#xf…

SpringCloud系列教程(十四):Sentinel持久化

Sentinel之前已经搭建和应用成功了&#xff0c;但是它有一个很大的缺点就是官方没有提供持久化的方案&#xff0c;从项目源码上看感觉这款工具也没有完成的太好&#xff0c;所以需要我们去对它进行二次开发。要补充的功能大概如下&#xff1a; 1、将Sentinel接入nacos中&#…

Go语言环境搭建并执行第一个Go程序

目录 一、Windows环境搭建 二、vscode安装插件 三、运行第一个go程序 一、Windows环境搭建 下载Go&#xff1a;All releases - The Go Programming Language 这里是Windows搭建&#xff0c;选择的是windows-amd64.msi&#xff0c;也可以选择zip直接解压缩到指定目录 选择msi…

Java数据结构第二十三期:Map与Set的高效应用之道(二)

专栏&#xff1a;Java数据结构秘籍 个人主页&#xff1a;手握风云 目录 一、哈希表 1.1. 概念 1.2. 冲突 1.3. 避免冲突 1.4. 解决冲突 1.5. 实现 二、OJ练习 2.1. 只出现一次的数字 2.2. 随机链表的复制 2.3. 宝石与石头 一、哈希表 1.1. 概念 顺序结构以及平衡树中…

OpenHarmony子系统开发 - Rust编译构建指导

OpenHarmony子系统开发 - Rust编译构建指导 一、Rust模块配置规则和指导 概述 Rust是一门静态强类型语言&#xff0c;具有更安全的内存管理、更好的运行性能、原生支持多线程开发等优势。Rust官方也使用Cargo工具来专门为Rust代码创建工程和构建编译。 OpenHarmony为了集成C…

STM32驱动代码规范化编写指南(嵌入式C语言方向)

点击下面图片&#xff0c;为您提供全新的嵌入式学习路线 文章目录 一、命名规范体系1.1 变量/函数命名1.2 宏定义规范1.3 类型定义 二、代码结构组织2.1 文件组织结构2.2 头文件规范模板 三、注释体系构建3.1 Doxygen风格示例3.2 复杂逻辑注释 四、硬件抽象层设计4.1 寄存器封…

Trae与Builder模式初体验

说明 下载的国际版&#xff1a;https://www.trae.ai/ 建议 要选新模型 效果 还是挺不错的&#xff0c;遇到问题反馈一下&#xff0c;AI就帮忙解决了&#xff0c;真是动动嘴&#xff08;打打字就行了&#xff09;&#xff0c;做些小的原型效果或演示Demo很方便呀&#xff…

【设计模式】《设计模式:可复用面向对象软件的基础》:设计模式怎样解决设计问题?

文章目录 ⭐前言⭐一、设计模式怎样解决设计问题&#xff1f;&#x1f31f;1、寻找合适的对象&#x1f31f;2、决定对象的粒度&#x1f31f;3、指定对象接口&#x1f31f;4、描述对象的实现&#x1f31f;5、运用复用机制✨(1)针对接口编程&#xff0c;而不是针对实现编程。✨(2…

【项目管理git】git学习

ps&#xff1a;所有东西都是个人理解 文章目录 一、git是什么&#xff0c;它用来做什么&#xff1f;二、相关知识库2.1 简单的linux指令2.2 git配置指令2.3 git常见的指令2.3.1 Git的上传原理2.3.2 版本回退相关内容 2.4 设置远程地址&#xff0c;本地上传到github2.4.1 ssh相…

python速通小笔记-------1.容器

1.字符串的标识 字符串需要用“”标识。 与c不同&#xff0c;python 写变量时 不需要标明数据类型每一行最后不需要加&#xff1b; 2.print函数的使用 与c中的printf函数一致 3.运算符 4.字符串str操作 1. 实现字符串拼接 2.% 实现字符串初始化 %s占位会把变量强制转变为…

零基础上手Python数据分析 (2):Python核心语法快速入门

写在前面 场景:每周销售数据报表整理 任务描述: 你需要每周从多个Excel文件中汇总销售数据,计算各项指标(销售额、订单量、客单价等),并生成周报。Excel操作痛点: 文件太多,手动打开复制粘贴,效率低下,容易出错。 多个Excel文件,每个都要打开、筛选、复制数据,重复…

【PHP】获取PHP-FPM的状态信息

文章目录 一、前言二、环境三、过程1&#xff09;修改PHP-FPM配置文件2&#xff09;修改Nginx配置文件3&#xff09;访问页面4&#xff09;修改状态页面端口 一、前言 PHP-FPM内置有一个状态页面&#xff0c;通过这个页面可以获取到FPM的一些状态信息&#xff08;见下图&#…

搭建Spring Boot Admin监控系统

什么是Spring Boot Admin Spring Boot Admin 是一个用于管理和监控 Spring Boot 应用程序的开源工具。它提供了一个用户友好的 Web 界面&#xff0c;用于集中管理和监控多个 Spring Boot 应用程序的运行状态、健康状况、日志、配置等信息。 Spring Boot Admin 的核心功能 应用…

[CISCN 2022 初赛]ezpop(没成功复现)

打开在线环境可以看到&#xff1a; 记得之前做过一个类似的就是有点像照着漏洞去复现。应该可以直接在网上找到链子去打。 www.zip查看路由是 Index/test&#xff0c;然后 post 传参 a&#xff1a; exp&#xff08;参考了别的大神的wp&#xff09;&#xff1a; <?php //…

C 语 言 --- 二 维 数 组 的 应 用

C 语 言 --- 二 维 数 组 的 应 用 第 一 题 - - - 冒 泡 排 序冒 泡 排 序冒 泡 排 序 的 原 理 第 二 题 - - - 回 型 矩 阵特 点 第 三 题 - - - 蛇 形 矩 阵总结 &#x1f4bb;作者简介&#xff1a;曾 与 你 一 样 迷 茫&#xff0c;现 以 经 验 助 你 入 门 C 语 言 &…

5G核心网实训室搭建方案:轻量化部署与虚拟化实践

5G核心网实训室 随着5G技术的广泛应用&#xff0c;行业对于5G核心网人才的需求日益增长。高校、科研机构和企业纷纷建立5G实训室&#xff0c;以促进人才培养、技术创新和行业应用研究。IPLOOK凭借其在5G核心网领域的深厚积累&#xff0c;提供了一套高效、灵活的5G实训室搭建方…