网站设计文章,国际转运网站建设,站长工具seo综合查询全面解析,外包加工网吧请求参数传json数组#xff0c;后端采用#xff08;pojo#xff09;接收的前提条件#xff1a;
1.pom.xml文件加入坐标依赖#xff1a;jackson-databind 2.Spring Boot 的启动类加注解#xff1a;EnableWebMvc 3.Spring Boot 的Controller接受参数采用#xff1a;Reque…请求参数传json数组后端采用pojo接收的前提条件
1.pom.xml文件加入坐标依赖jackson-databind 2.Spring Boot 的启动类加注解EnableWebMvc 3.Spring Boot 的Controller接受参数采用RequestBody 4.postman入参采用json格式
备注 此处省略pom文件加入坐标依赖和启动类加注解EnableWebMvc 具体可查看 【Spring Boot】请求参数传json对象后端采用pojoCRUD案例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 ListConfig config) {try {return xxxListService.addTest(config);} catch (Exception e) {log.error(Controller addTest is error: e.getMessage(), e);return Result.failure(测试成功);}}
Service类 //新增Result addTest(ListConfig config);ServiceImpl类 //新增Overridepublic Result addTest(ListConfig config) {ListMapString, Object res new ArrayList();xxxListMapper.addTest(config);return Result.success().result(res);}
Mapper类 //新增void addTest(Param(configs) ListConfig config);Mapper.xml类
!-- 新增 --insert idaddTestINSERT IGNORE INTO xxx_other_list_dic(dicNameFirst,dicValueFirst,dicNameSecond,dicValueSecond,dicType,isEnable)VALUESforeach collectionconfigs itemconfig separator,(#{config.dicNameFirst},#{config.dicValueFirst},#{config.dicNameSecond},#{config.dicValueSecond},#{config.dicType},#{config.isEnable})/foreach/insert
postman接口测试完成数据已新增