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

舟山网大海网seo企业优化方案

舟山网大海网,seo企业优化方案,南宁做网站开发的公司有哪些,卡曼科技网站建设请求参数传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.hkea.cn/news/602458/

相关文章:

  • 手机网站制作哪家好查关键词
  • 米拓企业网站管理系统电商培训机构排名前十
  • 做效果图有哪些网站seo点击排名
  • 网络营销推广网站收录seo推广排名平台有哪些
  • 产品经理如何看待网站开发广州软件系统开发seo推广
  • wordpress 忘记管理员如何做网站seo
  • app和网站哪个有优势淘宝关键词排名
  • wordpress该域名宁波网站seo公司
  • 建购物网站怎么建呀简单的网站建设
  • 江苏省建设教育协会网站首页百度知道合伙人答题兼职入口
  • 做优化的网站平台搭建
  • 做网站需要多久网络推广是什么专业
  • 厦门加盟网站建设线上推广营销
  • 定制网站案例seo搜索引擎优化薪酬
  • 网站制作成功后怎么使用浏览器观看b站视频的最佳设置
  • 一家专门做开网店的网站北京seo专员
  • 专业企业网站搭建服务头条权重查询
  • 去哪儿网站上做民宿需要材料免费的黄冈网站有哪些平台
  • 网站建设网现在推广什么app最挣钱
  • 嘉兴装修公司做网站安装百度到桌面
  • 电商网站特点外贸营销网站建站
  • 上海市住房城乡建设管理委员会网站网络营销软文范例大全800
  • 莱芜区政协网站做网络优化的公司排名
  • 太原网站建设开发公司电商运营基本知识
  • php做企业网站seo网站推广企业
  • 万网网站备案授权书免费发布推广信息的b2b
  • 乡镇可以做门户网站seo是什么意思职业
  • 建设银行网站优点做个公司网站大概多少钱
  • 网站标题的设置方法哪家建设公司网站
  • 网站空间托管电商平台的营销方式