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

网站开发知识视频教程办公室装修设计及报价

网站开发知识视频教程,办公室装修设计及报价,c 网站建设综合报告,西安网站建设是什么文章目录 一、概述二、编码实现1. pom文件引入组件2. 核心代码 三、功能测试1. 测试文件2. 测试代码 四#xff0c;完整代码 一、概述 带有API接口交互的web项目开发过程中#xff0c;json字符串与javaBean对象之间的相互转换是比较常见的需求#xff0c;基于jackson Objec… 文章目录 一、概述二、编码实现1. pom文件引入组件2. 核心代码 三、功能测试1. 测试文件2. 测试代码 四完整代码 一、概述 带有API接口交互的web项目开发过程中json字符串与javaBean对象之间的相互转换是比较常见的需求基于jackson ObjectMapper 实现的工具类较好的满足了此需求。 二、编码实现 1. pom文件引入组件 dependencygroupIdorg.springframework/groupIdartifactIdspring-webflux/artifactIdversion5.2.3.RELEASE/version/dependencydependencygroupIdio.projectreactor.netty/groupIdartifactIdreactor-netty/artifactIdversion0.9.4.RELEASE/version/dependencydependencygroupIdorg.apache.logging.log4j/groupIdartifactIdlog4j-slf4j-impl/artifactIdversion2.12.1/version/dependencydependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion2.10.2/version/dependencydependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.10/version/dependencydependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.5/version/dependencydependencygroupIdorg.junit.jupiter/groupIdartifactIdjunit-jupiter-api/artifactIdversion5.5.2/versionscopetest/scope/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.12/versionscopeprovided/scope/dependency2. 核心代码 JsonBeanUtils import java.io.IOException;import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper;/*** JsonBean转换工具* * author 00fly**/ public class JsonBeanUtils {private static ObjectMapper objectMapper new ObjectMapper();/*** bean转json字符串* * param bean* return* throws IOException*/public static String beanToJson(Object bean)throws IOException{String jsonText objectMapper.writeValueAsString(bean);return objectMapper.readTree(jsonText).toPrettyString();}/*** json字符串转bean* * param jsonText* return* throws IOException*/public static T T jsonToBean(String jsonText, ClassT clazz)throws IOException{return objectMapper.readValue(jsonText, clazz);}/*** json字符串转bean* * param jsonText* return* throws IOException*/public static T T jsonToBean(String jsonText, JavaType javaType)throws IOException{return objectMapper.readValue(jsonText, javaType);}/*** json字符串转bean* * param jsonText* return* throws IOException*/public static T T jsonToBean(String jsonText, TypeReferenceT typeRef)throws IOException{return objectMapper.readValue(jsonText, typeRef);} } 三、功能测试 1. 测试文件 jdbc.properties druid.usernamesa druid.password druid.urljdbc:h2:mem:hello;database_to_upperfalse druid.driverClassNameorg.h2.Driverdata.json {code: 200,message: success,traceId: fcd55497-864a-4d74-9db0-69a04655184f,data: {list: [{articleId: 135418954,title: java解析json复杂数据的两种思路,description: 萌新小明最近新开了CSDN博客蠢蠢欲动迫不及待的发表了几篇工作中积累下来的解决问题的涂鸦之作看着访问量慢慢涨起来心中暗暗窃喜。现在小明想每天23点记录一下每篇文章的访问量。。。,url: https://blog.csdn.net/qq_16127313/article/details/135418954,type: 1,top: false,forcePlan: false,viewCount: 828,commentCount: 0,editUrl: https://editor.csdn.net/md?articleId135418954,postTime: 2024-01-06 14:11:40,diggCount: 16,formatTime: 前天 14:11,picList: [https://img-blog.csdnimg.cn/direct/a409a0f4555c459fa05c00fd9ee0ea8c.png],collectCount: 19},{articleId: 135244727,title: java lambda表达式训练题一,description: Lambda 表达式也可称为闭包它是推动 Java 8 发布的最重要新特性。Lambda 允许把函数作为一个方法的参数函数作为参数传递进方法中。使用 Lambda 表达式可以使代码变的更加简洁紧凑。,url: https://blog.csdn.net/qq_16127313/article/details/135244727,type: 1,top: false,forcePlan: false,viewCount: 1238,commentCount: 0,editUrl: https://editor.csdn.net/md?articleId135244727,postTime: 2023-12-27 18:07:30,diggCount: 7,formatTime: 2023.12.27,picList: [https://img-blog.csdnimg.cn/direct/d59c68b950754e879914b5319cd1b53f.png],collectCount: 8},{articleId: 135173565,title: 二维码初体验 com.google.zxing 实现续 - web api封装,description: 在 二维码初体验 com.google.zxing 实现 我们实现了二维码的生成但是大部分情况下二维码的相关功能是作为API接口来提供服务的。我们下面便演示在springboot、Knife4j下封装api接口来实现二维码生成功能。如何使用下面的备份文件恢复成原始的项目代码请移步查阅神奇代码恢复工具-over-,url: https://blog.csdn.net/qq_16127313/article/details/135173565,type: 1,top: false,forcePlan: false,viewCount: 1904,commentCount: 0,editUrl: https://editor.csdn.net/md?articleId135173565,postTime: 2023-12-23 20:17:11,diggCount: 23,formatTime: 2023.12.23,picList: [https://img-blog.csdnimg.cn/direct/f0c994ca789a495a8c8c03d86d626f24.jpeg],collectCount: 23},{articleId: 135167613,title: 二维码初体验 com.google.zxing 实现,description: Java 操作二维码的开源项目很多如 SwetakeQRCode、BarCode4j、Zxing 等这边以Zxing 为例进行介绍。选择需要生成QR原始文件支持 “清除空白行及空格” 以减少二维码图片大小。支持输入文本内容直接生成二维码代码结构QrCodeUI: 完整版本代码SimpleQrCodeUI简化版本代码如何使用下面的备份文件恢复成原始的项目代码请移步查阅神奇代码恢复工具-over-,url: https://blog.csdn.net/qq_16127313/article/details/135167613,type: 1,top: false,forcePlan: false,viewCount: 1286,commentCount: 0,editUrl: https://editor.csdn.net/md?articleId135167613,postTime: 2023-12-23 13:52:23,diggCount: 6,formatTime: 2023.12.23,picList: [https://img-blog.csdnimg.cn/direct/d3eeac85857543869dce8967c570bdc4.jpeg],collectCount: 11},{articleId: 135135799,title: 【随笔】MD5加密字符串、文件apache、springframework实现,description: 【代码】【随笔】MD5加密字符串、文件commons-codec、springframework实现。,url: https://blog.csdn.net/qq_16127313/article/details/135135799,type: 1,top: false,forcePlan: false,viewCount: 1721,commentCount: 0,editUrl: https://editor.csdn.net/md?articleId135135799,postTime: 2023-12-21 17:29:54,diggCount: 9,formatTime: 2023.12.21,picList: [https://img-blog.csdnimg.cn/direct/dc26b7f1c731494f80c8c3b3badfa95d.jpeg],collectCount: 9}],total: 72} }2. 测试代码 import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Properties;import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.http.MediaType; import org.springframework.web.reactive.function.client.WebClient;import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.type.TypeFactory;import lombok.Data; import lombok.extern.slf4j.Slf4j;/*** JsonBeanUtils测试*/ Slf4j public class JsonBeanUtilsTest {static String jsonText;static Properties properties;static WebClient webClient;static String url;BeforeAllpublic static void init(){try{properties PropertiesLoaderUtils.loadProperties(new ClassPathResource(jdbc.properties));jsonText IOUtils.toString(new ClassPathResource(data.json).getURL(), StandardCharsets.UTF_8);webClient WebClient.builder().codecs(configurer - configurer.defaultCodecs().maxInMemorySize(-1)).build();url https://blog.csdn.net/community/home-api/v1/get-business-list?page1size5businessTypeblogusernameqq_16127313;}catch (IOException e){log.error(e.getMessage(), e);}}Testpublic void propsTest()throws IOException{String propsJson JsonBeanUtils.beanToJson(properties);log.info(propsJson : {} , propsJson);log.info(properties: {} , JsonBeanUtils.jsonToBean(propsJson, Properties.class));}Testpublic void beanToJson001()throws IOException{BlogData blogData JsonBeanUtils.jsonToBean(jsonText, BlogData.class);log.info(blogData: {} , blogData);log.info(blogData: {} , JsonBeanUtils.beanToJson(blogData));log.info(blogData.data: {} , JsonBeanUtils.beanToJson(blogData.getData()));log.info(blogData.data.list: {} , JsonBeanUtils.beanToJson(blogData.getData().getList()));}Testpublic void beanToJson002()throws IOException{String resp webClient.get().uri(url).acceptCharset(StandardCharsets.UTF_8).accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono(String.class).block();BlogData blogData JsonBeanUtils.jsonToBean(resp, BlogData.class);String jsonText JsonBeanUtils.beanToJson(blogData);log.info(blogData: {} , blogData);log.info(jsonText: {} , jsonText);}/*** 测试 JsonBeanUtils.jsonToBean(String jsonText, JavaType javaType)* * throws IOException*/Testpublic void jsonToBean001()throws IOException{BlogData blogData JsonBeanUtils.jsonToBean(jsonText, BlogData.class);String jsonStr JsonBeanUtils.beanToJson(blogData.getData().getList());// ListSubListJavaType javaType TypeFactory.defaultInstance().constructParametricType(List.class, SubList.class);ListSubList dataEntitys JsonBeanUtils.jsonToBean(jsonStr, javaType);log.info(dataEntitys: {} , dataEntitys);}/*** 测试 JsonBeanUtils.jsonToBean(String jsonText, TypeReferenceT typeRef)* * throws IOException*/Testpublic void jsonToBean002()throws IOException{BlogData blogData JsonBeanUtils.jsonToBean(jsonText, BlogData.class);String jsonStr JsonBeanUtils.beanToJson(blogData.getData().getList());// ListSubListTypeReferenceListSubList typeRef new TypeReferenceListSubList(){};ListSubList dataEntitys JsonBeanUtils.jsonToBean(jsonStr, typeRef);log.info(dataEntitys: {} , dataEntitys);} }Data class BlogData {private Integer code;private String message;private String traceId;private Record data; }Data class Record {private ListSubList list;private Long total; }Data class SubList {String articleId;String title;String description;String url;Integer type;String top;String forcePlan;Long viewCount;Long commentCount;String editUrl;String postTime;Long diggCount;String formatTime;Object picList;Long collectCount; } 四完整代码 如何使用下面的备份文件恢复成原始的项目代码请移步查阅神奇代码恢复工具 //goto pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.fly/groupIdartifactIdbase/artifactIdversion0.0.1/versionnamebase/namepropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingjava.version1.8/java.versionskipTeststrue/skipTests/propertiesdependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-webflux/artifactIdversion5.2.3.RELEASE/version/dependencydependencygroupIdio.projectreactor.netty/groupIdartifactIdreactor-netty/artifactIdversion0.9.4.RELEASE/version/dependencydependencygroupIdorg.apache.logging.log4j/groupIdartifactIdlog4j-slf4j-impl/artifactIdversion2.12.1/version/dependencydependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion2.10.2/version/dependencydependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.10/version/dependencydependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.5/version/dependencydependencygroupIdorg.junit.jupiter/groupIdartifactIdjunit-jupiter-api/artifactIdversion5.5.2/versionscopetest/scope/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.12/versionscopeprovided/scope/dependency/dependenciesbuildpluginsplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdversion3.10.1/versionconfigurationsource1.8/sourcetarget1.8/targetencodingUTF-8/encoding/configuration/plugin/plugins/build /project //goto src\main\java\com\fly\core\utils\JsonBeanUtils.java package com.fly.core.utils;import java.io.IOException;import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper;/*** JsonBean转换工具* * author 00fly**/ public class JsonBeanUtils {private static ObjectMapper objectMapper new ObjectMapper();/*** bean转json字符串* * param bean* return* throws IOException*/public static String beanToJson(Object bean)throws IOException{String jsonText objectMapper.writeValueAsString(bean);return objectMapper.readTree(jsonText).toPrettyString();}/*** json字符串转bean* * param jsonText* return* throws IOException*/public static T T jsonToBean(String jsonText, ClassT clazz)throws IOException{return objectMapper.readValue(jsonText, clazz);}/*** json字符串转bean* * param jsonText* return* throws IOException*/public static T T jsonToBean(String jsonText, JavaType javaType)throws IOException{return objectMapper.readValue(jsonText, javaType);}/*** json字符串转bean* * param jsonText* return* throws IOException*/public static T T jsonToBean(String jsonText, TypeReferenceT typeRef)throws IOException{return objectMapper.readValue(jsonText, typeRef);} } //goto src\main\resources\log4j2.xml ?xml version1.0 encodingUTF-8? configuration statusoff monitorInterval0appendersconsole nameConsole targetsystem_outpatternLayout pattern%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n //console/appendersloggersroot levelINFOappender-ref refConsole //root/loggers /configuration //goto src\test\java\com\fly\core\utils\JsonBeanUtilsTest.java package com.fly.core.utils;import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Properties;import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.http.MediaType; import org.springframework.web.reactive.function.client.WebClient;import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.type.TypeFactory;import lombok.Data; import lombok.extern.slf4j.Slf4j;/*** JsonBeanUtils测试*/ Slf4j public class JsonBeanUtilsTest {static String jsonText;static Properties properties;static WebClient webClient;static String url;BeforeAllpublic static void init(){try{properties PropertiesLoaderUtils.loadProperties(new ClassPathResource(jdbc.properties));jsonText IOUtils.toString(new ClassPathResource(data.json).getURL(), StandardCharsets.UTF_8);webClient WebClient.builder().codecs(configurer - configurer.defaultCodecs().maxInMemorySize(-1)).build();url https://blog.csdn.net/community/home-api/v1/get-business-list?page1size5businessTypeblogusernameqq_16127313;}catch (IOException e){log.error(e.getMessage(), e);}}Testpublic void propsTest()throws IOException{String propsJson JsonBeanUtils.beanToJson(properties);log.info(propsJson : {} , propsJson);log.info(properties: {} , JsonBeanUtils.jsonToBean(propsJson, Properties.class));}Testpublic void beanToJson001()throws IOException{BlogData blogData JsonBeanUtils.jsonToBean(jsonText, BlogData.class);log.info(blogData: {} , blogData);log.info(blogData: {} , JsonBeanUtils.beanToJson(blogData));log.info(blogData.data: {} , JsonBeanUtils.beanToJson(blogData.getData()));log.info(blogData.data.list: {} , JsonBeanUtils.beanToJson(blogData.getData().getList()));}Testpublic void beanToJson002()throws IOException{String resp webClient.get().uri(url).acceptCharset(StandardCharsets.UTF_8).accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono(String.class).block();BlogData blogData JsonBeanUtils.jsonToBean(resp, BlogData.class);String jsonText JsonBeanUtils.beanToJson(blogData);log.info(blogData: {} , blogData);log.info(jsonText: {} , jsonText);}/*** 测试 JsonBeanUtils.jsonToBean(String jsonText, JavaType javaType)* * throws IOException*/Testpublic void jsonToBean001()throws IOException{BlogData blogData JsonBeanUtils.jsonToBean(jsonText, BlogData.class);String jsonStr JsonBeanUtils.beanToJson(blogData.getData().getList());// ListSubListJavaType javaType TypeFactory.defaultInstance().constructParametricType(List.class, SubList.class);ListSubList dataEntitys JsonBeanUtils.jsonToBean(jsonStr, javaType);log.info(dataEntitys: {} , dataEntitys);}/*** 测试 JsonBeanUtils.jsonToBean(String jsonText, TypeReferenceT typeRef)* * throws IOException*/Testpublic void jsonToBean002()throws IOException{BlogData blogData JsonBeanUtils.jsonToBean(jsonText, BlogData.class);String jsonStr JsonBeanUtils.beanToJson(blogData.getData().getList());// ListSubListTypeReferenceListSubList typeRef new TypeReferenceListSubList(){};ListSubList dataEntitys JsonBeanUtils.jsonToBean(jsonStr, typeRef);log.info(dataEntitys: {} , dataEntitys);} }Data class BlogData {private Integer code;private String message;private String traceId;private Record data; }Data class Record {private ListSubList list;private Long total; }Data class SubList {String articleId;String title;String description;String url;Integer type;String top;String forcePlan;Long viewCount;Long commentCount;String editUrl;String postTime;Long diggCount;String formatTime;Object picList;Long collectCount; } //goto src\test\resources\jdbc.properties druid.usernamesa druid.password druid.urljdbc:h2:mem:hello;database_to_upperfalse druid.driverClassNameorg.h2.Driver //goto src\test\resources\log4j2.xml ?xml version1.0 encodingUTF-8? configuration statusoff monitorInterval0appendersconsole nameConsole targetsystem_outpatternLayout pattern%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n //console/appendersloggersroot levelINFOappender-ref refConsole //root/loggers /configuration 有任何问题和建议都可以向我提问讨论,大家一起进步谢谢! -over-
http://www.hkea.cn/news/14547250/

相关文章:

  • 哪里有网站建设中心高端网站建设软件开发
  • 同程网站建设分析学子网站建设
  • 免费推广自己的网站网站界面美观度
  • 唐山做网站网站推广应该坚持什么策略
  • 电商网站可维护性广州建立网站的公司网站
  • 鹤壁网站建设公司wordpress 黄聪
  • 深圳做棋牌网站建设哪家技术好河南工程建设协会网站
  • 网站建设是干什么苏州网站设计公司有哪些
  • 深圳营销型网站建庆阳北京网站建设
  • 修改网站图标wap网站是什么意思
  • 学技能的免费网站一个服务器可以备案几个网站
  • 网站开发如何处理兼容性问题wordpress 问答主题
  • 网站改名工信部需要怎么做在哪找公众号
  • 腾讯云网站建设流程网站的底部导航栏怎么做
  • 点的排版设计网站有祥云网站
  • 云服务器可以做图片外链网站吗中国空间站天宫课堂
  • 美食网站建设背景介绍二维码生成器官网
  • 湖南网站建设找拉米拉下载wix做的网站
  • 外贸网站设计方案中国住房和城乡建设部网站证书查询
  • 网站建设正规公司wordpress 建站群
  • 招聘网站免费平台长沙景点大全 长沙景点排名
  • windows建立网站南通高端网站建设咨询
  • 免费建设com网站wordpress漏洞利用2016
  • 芜湖建设公司网站那些网站是做金融行业
  • 广州移动网站开发成都高新区建设局网站
  • 个人网站模板打包下载深圳市盐田区建设局网站
  • 响应式网站模板dede企业型网站建设咨询电话
  • 临清建设网站淄博网站设计策划方案维护
  • 我的世界做图片网站张雪峰谈工业设计专业
  • 制作一个门户网站需要多少钱网站页面设计规范