【Spring Boot】请求参数传json数组,后端采用(pojo)新增案例(103)

news/2025/3/14 17:13:25/

请求参数传json数组,后端采用(pojo)接收的前提条件:

1.pom.xml文件加入坐标依赖:jackson-databind
2.Spring Boot 的启动类加注解:@EnableWebMvc
3.Spring Boot 的Controller接受参数采用:@RequestBody
4.postman入参采用json格式

备注:
此处省略:pom文件加入坐标依赖和启动类加注解:@EnableWebMvc
具体可查看:
【Spring Boot】请求参数传json对象,后端采用(pojo)CRUD案例(102)

postman入参采用json格式:传入json数组
在这里插入图片描述
POJO类:


import lombok.Data;@Data
public class Config {private int seqId;private int sortId;private String interfaceType;private String dicNameFirst;private int dicValueFirst;private String dicNameSecond;private int dicValueSecond;private String dicType;private String isEnable;
}

Controller接受参数采用:@RequestBody
Controller类:使用 @RequestBody List< Config > config
备注:为了便于测试:Controller类只写了一个接口(实际开发可不要这样写噢)

	/** 请求参数传递json数据:json对象(POJO)**/@PostMapping(value = "/addTest")@AuthInterceptor("mg:get:addTest")public Result addTest(@RequestBody List<Config> config) {try {return xxxListService.addTest(config);} catch (Exception e) {log.error("Controller addTest is error===:" + e.getMessage(), e);return Result.failure("测试成功");}}

Service类:

	//新增Result addTest(List<Config> config);

ServiceImpl类:

	//新增@Overridepublic Result addTest(List<Config> config) {List<Map<String, Object>> res = new ArrayList<>();xxxListMapper.addTest(config);return Result.success().result(res);}

Mapper类:

	//新增void addTest(@Param("configs") List<Config> config);

Mapper.xml类:

<!-- 新增 --><insert id="addTest">INSERT IGNORE INTO xxx_other_list_dic(dicNameFirst,dicValueFirst,dicNameSecond,dicValueSecond,dicType,isEnable)VALUES<foreach collection="configs" item="config" separator=",">(#{config.dicNameFirst},#{config.dicValueFirst},#{config.dicNameSecond},#{config.dicValueSecond},#{config.dicType},#{config.isEnable})</foreach></insert>

postman接口测试完成:数据已新增

在这里插入图片描述


http://www.ppmy.cn/news/1001406.html

相关文章

django使用ztree实现树状结构效果,子节点实现动态加载(l懒加载)

一、实现的效果 由于最近项目中需要实现树状结构的效果,考虑到ztree这个组件大家用的比较多,因此打算在django项目中集成ztree来实现树状的效果。最终实现的示例效果如下: 点击父节点,如果有子节点,则从后台动态请求数据,然后显示出子节点的数据。 二、实现思路 …

JVM面试突击班2

JVM面试突击班2 对象被判定为不可达对象之后就“死”了吗 对象的生命周期 创建阶段 &#xff08;1&#xff09;为对象分配存储空间 &#xff08;2&#xff09;开始构造对象 &#xff08;3&#xff09;从超类到子类对static成员进行初始化 &#xff08;4&#xff09;超类成…

SAS-数据集SQL垂直(纵向)合并

一、SQL垂直合并的基本语法 一个selectt对应一个表&#xff0c;select之间用set-operator连接&#xff0c;set-operator包括&#xff1a;except&#xff08;期望&#xff09;、intersect&#xff08;相交&#xff09;、union&#xff08;合并&#xff09;&#xff0c;outer un…

Spring mvc:SpringServletContainerInitializer

SpringServletContainerInitializer实现了Servlet3.0规范中定义的ServletContainerInitializer&#xff1a; public interface ServletContainerInitializer {void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException; }SpringServletCont…

2023河南萌新联赛第(四)场 L.7是大奖?(数位DP基础)

文章目录 题目大意题解参考代码总结 题目大意 ( 1 ≤ l , r ≤ 1 0 18 ) (1\leq l,r\leq 10^{18}) (1≤l,r≤1018) 题解 由题目可得 ①&#xff1a;统计数字出现次数&#xff1b; ②&#xff1a;直接暴力计算无法得出&#xff1b; ③&#xff1a;输入给定区间。 满足使用数位…

如何从 html 页面调用在 javascript 模块 (type=module) 中声明的函数

首先&#xff0c;必须明确导出您的功能 export function greet() {alert("Hello from module"); } 其次&#xff0c;模块有它自己的范围&#xff08;这是模块的全部意义&#xff09;&#xff0c;因此您需要将函数添加到全局范围。因此&#xff0c;要做到这一点&…

企业真实的自动化框架?资深8年测试是如何设计实施的...

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 什么是框架&#…

docker 哨兵模式和集群模式安装Redis7.0.12

docker 哨兵模式和集群模式安装Redis7.0.12 1.下载镜像 1.1 配置阿里云加速源 墙外能访问https://hub.docker.com/_/redis 的可跳过 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 登录后选择左侧的镜像工具>镜像加速器&#xff0c;获取加速器地址&#…