当前位置: 首页 > news >正文

400元做网站送网推做餐饮的网站

400元做网站送网推,做餐饮的网站,杨浦区网站建设,兰州网站建设100请求参数传json对象,后端采用(map)接收的前提条件: 1.Spring Boot 的Controller接受参数采用:RequestBody 2.需要一个Json工具类,将json数据转成Map; 工具类:Json转Map import com…

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

1.Spring Boot 的Controller接受参数采用:@RequestBody
2.需要一个Json工具类,将json数据转成Map;

工具类:Json转Map


import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.beanutils.PropertyUtils;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;/*** 。* (1) 使用泛型方法:把json字符串转换为相应的JavaBean对象;*     转换为普通JavaBean:readValue(json,Student.class);* (2) List Map转换List 对象:如List<Student>,将第二个参数传递为Student;* (3) List 对象转换List Map:*     [].class.然后使用Arrays.asList();方法把得到的数组转换为特定类型的List;** @param jsonStr* @param valueType* @return* */public final class JsonUtils {private static ObjectMapper objectMapper;/*** (1) 使用泛型方法:把json字符串转换为相应的JavaBean对象;*     转换为普通JavaBean:readValue(json,Student.class);*/public static <T> T readValue(String jsonStr, Class<T> valueType) throws Exception {if (objectMapper == null) {objectMapper = new ObjectMapper();}return objectMapper.readValue(jsonStr, valueType);}/***(2).List Map转换List 对象:如List<Student>,将第二个参数传递为Student对象;*    map转换为bean*/public static Object mapToObject(Map<String, String> map, Class<?> beanClass) throws Exception {if (map == null)return null;Object obj = beanClass.newInstance();BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();for (PropertyDescriptor property : propertyDescriptors) {Method setter = property.getWriteMethod();if (setter != null) {setter.invoke(obj, map.get(property.getName()));}}return obj;}/***(3).List 对象转换List Map:*    [].class.然后使用Arrays.asList();方法把得到的数组转换为特定类型的List;*    bean转换为map*/public static <T> List<Map<String, Object>> listConvert(List<T> list){List<Map<String, Object>> list_map = new ArrayList<Map<String, Object>>();if (CollectionUtils.isNotEmpty(list)) {list.forEach(item ->{Map<String, Object> map = null;try {map = PropertyUtils.describe(item);} catch (IllegalAccessException e) {throw new RuntimeException(e);} catch (InvocationTargetException e) {throw new RuntimeException(e);} catch (NoSuchMethodException e) {throw new RuntimeException(e);}list_map.add(map);});}return list_map;}
}

Controller类:@RequestBody
备注:为了便于测试:Controller类只写了一个接口(实际开发可不要这样写噢)

** 请求参数传递json数据:json对象(map)**/@PostMapping(value = "/addTest")@AuthInterceptor("mg:get:addTest")public Result addTest(@RequestBody String param) {try {Map<String, Object> paramMap = JsonUtils.readValue(param, Map.class);return xxxListService.addTest(paramMap);} catch (Exception e) {log.error("Controller addTest is error===:" + e.getMessage(), e);return Result.failure("测试成功");}}

Service类:

	Result addTest(Map<String, Object> paramMap);

ServiceImpl类:

@Overridepublic Result addTest(Map<String, Object> paramMap) {List<Map<String, Object>> res = new ArrayList<>();String interfaceType = String.valueOf(paramMap.get("interfaceType"));if(interfaceType.equals("add")){xxxListMapper.addTest(paramMap);}else if(interfaceType.equals("del")){xxxListMapper.delTest(paramMap);}else if(interfaceType.equals("modify")){xxxListMapper.modifyTest(paramMap);}else if(interfaceType.equals("sel")){res = xxxListMapper.selTest(paramMap);}return Result.success().result(res);}

Mapper类:

//新增void addTest(Map<String, Object> paramMap);//删除void delTest(Map<String, Object> paramMap);//修改void modifyTest(Map<String, Object> paramMap);//查询List<Map<String, Object>> selTest(Map<String, Object> paramMap);

Mapper.xml类

<!-- 新增 --><insert id="addTest" parameterType="map">INSERT IGNORE INTO xxx_other_list_dic(dicNameFirst,dicValueFirst,dicNameSecond,dicValueSecond,dicType,isEnable)VALUES(#{dicNameFirst},#{dicValueFirst},#{dicNameSecond},#{dicValueSecond},#{dicType},#{isEnable})</insert><!-- 删除 --><select id="delTest" parameterType="map">deleteFROM xxx_other_list_dic where<if test = "null != seqId and '' != seqId">seqId = #{seqId}</if></select><!-- 修改 --><update id="modifyTest" parameterType="map">update xxx_other_list_dic<set><if test = "null != sortId and '' != sortId">sortId = #{sortId},</if><if test = "null != isEnable and '' != isEnable">isEnable = #{isEnable}</if></set>where<if test = "null != seqId and '' != seqId">seqId = #{seqId}</if></update><!-- 查询 --><select id="selTest" parameterType="map" resultType="map">SELECT *FROM xxx_other_list_dic where 1 = 1<if test="null != dicNameFirst and '' != dicNameFirst">and dicNameFirst = #{dicNameFirst}</if><if test="null != dicValueFirst and '' != dicValueFirst">and dicValueFirst = #{dicValueFirst}</if><if test="null != dicNameSecond and '' != dicNameSecond">and dicNameSecond = #{dicNameSecond}</if><if test="null != dicValueSecond and '' != dicValueSecond">and dicValueSecond = #{dicValueSecond}</if><if test="null != dicType and '' != dicType">and dicType = #{dicType}</if><if test="null != isEnable and '' != isEnable">and isEnable = #{isEnable}</if>order by sortId</select>

Postman 接口测试:
新增:
在这里插入图片描述
在这里插入图片描述
修改:
在这里插入图片描述
在这里插入图片描述
查询:
在这里插入图片描述
删除:
在这里插入图片描述
在这里插入图片描述

http://www.yayakq.cn/news/230147/

相关文章:

  • 郑州做网站排名公司微信商城小程序怎么自己开发
  • 免费网站管理系统下载企业网站的短视频中心模板
  • 重庆做模块网站新加坡网站后缀
  • c 网站开发用的人多吗网上打广告
  • 个人网站优秀作品义务加工网
  • pw域名网站微信h5制作软件
  • 烟台网站建设方案书wordpress建博客网站
  • 怎么建网站卖产品网站后台编辑框不显示
  • 关于网站建设的话术网站建设万禾
  • 家具商务网站策划案网站导航html源码
  • 外贸高端网站设计公司外贸电商网站开发价格
  • 网站建设倒计时单页源码个人网站模板html代码免费
  • 永年做网站开发区网站制作公司
  • 郑州仿站模板网站建设北京到广州动卧
  • 开发一个微信小程序多少费用成都百度推广排名优化
  • 建设一个网站要钱吗多推网怎么推广
  • 手机端网站建设的注意事项网站维护有啥用
  • 沈阳模板建站公司有哪些做内贸的电子商务网站典型有
  • 哪个网站有做彩平的材质贴图谈谈设计和建设网站体会
  • 什么博客可以做网站做文案需要用到的网站
  • 主营网站开发WORDPRESS导购主题:WYZDG
  • 新的网站平台如何做地推网站建设中两个月了
  • 手表网站app推荐免费建立网站教程
  • 家政公司网站怎么做高端品牌包包
  • 哈尔滨寸金网站建设价格公司网站本地如何弄
  • 广州开发网站建设e福州官方网站
  • 网站建设柒金手指下拉二一视频网站 外链
  • ECMS做的网站杭州网站推广找哪家
  • php网站开发的技术框架高中信息技术课程做网站
  • 上海网站建设团队浏览器2345网址导航下载安装