spring cloud 入門(mén)操作手冊(cè)(全_第1頁(yè)
spring cloud 入門(mén)操作手冊(cè)(全_第2頁(yè)
spring cloud 入門(mén)操作手冊(cè)(全_第3頁(yè)
spring cloud 入門(mén)操作手冊(cè)(全_第4頁(yè)
spring cloud 入門(mén)操作手冊(cè)(全_第5頁(yè)
已閱讀5頁(yè),還剩284頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、 HYPERLINK / spring boot 2.1.4spring cloud Greenwich.SR1課前資料 HYPERLINK /noteshare?id=42c30d89f50ee57a54e013f2b8fc4fe5&sub=601E92B306E6412C81EAF36637A7029A STS 插件安裝 HYPERLINK /noteshare?id=45bc7db2ad61efd163281d2e5845e8dd&sub=DE9C5A3EE14F4645997E9FB91CD8D1BF lombok 插件安裝 HYPERLINK /noteshare?id=1cd70f

2、3144281cce5e40c46386d2d747&sub=8C0D7F77FA1C4429B36554A9CE246D08 maven settings.xmlspring cloud 入門(mén)手冊(cè)(全)分段文檔鏈接: HYPERLINK /ynoteshare1/index.html?id=888d5f3055ee81001cbf3eefa0c7be4d&type=note 一四 HYPERLINK /ynoteshare1/index.html?id=32e46c37f4a3f22ea1b3a6c7b9c6f27d&type=note 五十 HYPERLINK /ynoteshare1/i

3、ndex.html?id=6fe9c30e28578bb18370c1acd0a3c822&type=note 十一十四 HYPERLINK /ynoteshare1/index.html?id=95a492ab5a94de426e64d734e6e4199f&type=note 十五二十 HYPERLINK /ynoteshare1/index.html?id=49dee3b0fc0a40637d6d4be10dc6da5e&type=note 二十一二十六目錄目錄spring cloud 介紹spring cloud 技術(shù)組成Spring Cloud 對(duì)比 Dubbo 一、service

4、- 服務(wù)二、commons 通用項(xiàng)目新建 maven 項(xiàng)目pom.xmljava 源文件pojoItemUser OrderserviceItemServiceUserService OrderServiceutilCookieUtilJsonUtil JsonResult三、item service 商品服務(wù)新建 spring boot 起步項(xiàng)目選擇依賴(lài)項(xiàng)pom.xml application.yml 主程序java 源文件ItemServiceImplItemController 四、user service 用戶服務(wù)新建 spring boot 起步項(xiàng)目選擇依賴(lài)項(xiàng)pom.xmlappli

5、cation.yml 主程序java源文件UserServiceImplUserController五、order service 訂單服務(wù)新建 spring boot 起步項(xiàng)目選擇依賴(lài)項(xiàng)pom.xml applicatoin.yml 主程序java 源文件OrderServiceImplOrderController 六、service 訪問(wèn)測(cè)試七、eureka 注冊(cè)與發(fā)現(xiàn)創(chuàng)建 eureka server 項(xiàng)目:sp05-eurekapom.xml application.yml 主程序修改 hosts 文件,添加 eureka 域名映射啟動(dòng),并訪問(wèn)測(cè)試八、service provider

6、服務(wù)提供者pom.xml 添加 eureka 客戶端依賴(lài)application.yml 添加 eureka注冊(cè)配置主程序啟用服務(wù)注冊(cè)發(fā)現(xiàn)客戶端啟動(dòng),并訪問(wèn) eureka 查看注冊(cè)信息九、ribbon 服務(wù)消費(fèi)者新建 sp06-ribbon 項(xiàng)目pom.xml application.yml 主程序RibbonController啟動(dòng)服務(wù),并訪問(wèn)測(cè)試十、eureka 和 “服務(wù)提供者”的高可用eureka 高可用application.ymlfiles.activeSTS 配置啟動(dòng)參數(shù)訪問(wèn) eureka 服務(wù)器,查看注冊(cè)信息eureka客戶端注冊(cè)時(shí),向兩個(gè)服務(wù)器注冊(cè)item-service 高可

7、用application.yml 配置啟動(dòng)參數(shù) 啟動(dòng)測(cè)試十一、ribbon 負(fù)載均衡添加 ribbon 起步依賴(lài)(可選)LoadBalancedRestTemplate 設(shè)置訪問(wèn)路徑設(shè)置為服務(wù)id 訪問(wèn)測(cè)試ribbon 重試pom.xml 添加 spring-retry 依賴(lài)application.yml 配置 ribbon 重試主程序設(shè)置 RestTemplate 的請(qǐng)求工廠的超時(shí)屬性item-service 的 ItemController 添加延遲代碼,以便測(cè)試 ribbon 的重試機(jī)制訪問(wèn),測(cè)試 ribbon 重試機(jī)制十二、ribbon + hystrix 斷路器微服務(wù)宕機(jī)時(shí),ribb

8、on 無(wú)法轉(zhuǎn)發(fā)請(qǐng)求復(fù)制 sp06-ribbon 項(xiàng)目,命名為sp07-hystrix 修改 pom.xml添加 hystrix 起步依賴(lài)修改 application.ymlEnableCircuitBreaker主程序添加RibbonController 中添加降級(jí)方法hystrix 短路超時(shí)設(shè)置啟動(dòng)項(xiàng)目進(jìn)行測(cè)試十三、hystrix dashboard 斷路器儀表盤(pán)啟用 hystrix 斷路器sp07-hystrix 項(xiàng)目添加 actuator,并暴露 hystrix 監(jiān)控端點(diǎn)pom.xml 添加 actuator 依賴(lài)調(diào)整 application.yml 配置,并暴露 hystrix 監(jiān)控端

9、點(diǎn)訪問(wèn) actuator 路徑,查看監(jiān)控端點(diǎn)新建 sp08-hystrix-dashboard 項(xiàng)目pom.xmlapplication.ymlEnableHystrixDashboardEnableDiscoveryClient主程序添加和啟動(dòng),并訪問(wèn)測(cè)試訪問(wèn) hystrix dashboard填入 hystrix 的監(jiān)控端點(diǎn),開(kāi)啟監(jiān)控hystrix 熔斷使用 apache 的并發(fā)訪問(wèn)測(cè)試工具 abhystrix 配置十四、feign 整合ribbon+hystrix 新建 sp09-feign 項(xiàng)目pom.xmlapplication.ymlEnableDiscoveryClientEna

10、bleFeignClients主程序添加和java 源文件feign 聲明式客戶端ItemFeignService UserFeignService OrderFeignService FeignController啟動(dòng)服務(wù),并訪問(wèn)測(cè)試十五、feign + ribbon 負(fù)載均衡和重試application.yml 配置 ribbon 超時(shí)和重試啟動(dòng)服務(wù),訪問(wèn)測(cè)試 十六、feign + hystrix 降級(jí)feign 啟用 hystrixapplication.yml 添加配置可以添加配置,暫時(shí)減小降級(jí)超時(shí)時(shí)間,以便后續(xù)對(duì)降級(jí)進(jìn)行測(cè)試feign + hystrix 降級(jí)降級(jí)類(lèi)ItemFeign

11、ServiceFBUserFeignServiceFB OrderFeignServiceFBfeign service 接口中指定降級(jí)類(lèi)ItemFeignService UserFeignService OrderFeignService啟動(dòng)服務(wù),訪問(wèn)測(cè)試十七、feign + hystrix 監(jiān)控和熔斷測(cè)試修改sp09-feign項(xiàng)目pom.xml 添加 hystrix 起步依賴(lài)EnableCircuitBreaker主程序添加hystrix.streamsp09-feign 配置 actuator,暴露actuator 依賴(lài)application.yml 暴露啟動(dòng)服務(wù),查看監(jiān)控端點(diǎn)hyst

12、rix dashboard熔斷測(cè)試監(jiān)控端點(diǎn)hystrix.stream端點(diǎn)十八、order service 調(diào)用商品庫(kù)存服務(wù)和用戶服務(wù)pom.xmlapplication.yml 主程序ItemFeignService UserFeignServiceItemFeignServiceFBUserFeignServiceFB OrderServiceImplorder-service 配置啟動(dòng)參數(shù)啟動(dòng)服務(wù),訪問(wèn)測(cè)試hystrix dashboard 監(jiān)控 order service 斷路器十九、hystrix + turbine 集群聚合監(jiān)控新建 sp10-turbine 項(xiàng)目pom.xml a

13、pplication.yml 主程序訪問(wèn)測(cè)試二十、zuul API網(wǎng)關(guān)新建 sp11-zuul 項(xiàng)目pom.xml applicatoin.yml 主程序啟動(dòng)服務(wù),訪問(wèn)測(cè)試zuul + ribbon 負(fù)載均衡zuul + ribbon 重試pom.xml 添加 spring-retry 依賴(lài)配置 zuul 開(kāi)啟重試,并配置 ribbon 重試參數(shù)zuul + hystrix 降級(jí)創(chuàng)建降級(jí)類(lèi)ItemServiceFallback OrderServiceFallbackzuul + hystrix 熔斷zuul + hystrix dashboard 監(jiān)控暴露 hystrix.stream 監(jiān)控

14、端點(diǎn)開(kāi)啟監(jiān)控zuul + turbine 聚合監(jiān)控熔斷測(cè)試二十一、zuul 請(qǐng)求過(guò)濾定義過(guò)濾器,繼承 ZuulFilter訪問(wèn)測(cè)試二十二、zuul Cookie過(guò)濾二十三、config 配置中心github 上存放配置文件新建 Project,命名為 config將sp02,sp03,sp04,sp11四個(gè)項(xiàng)目的yml配置文件,復(fù)制到config項(xiàng)目,并改名將 config 項(xiàng)目上傳到 githubconfig 服務(wù)器新建 sp12-config 項(xiàng)目pom.xml application.ymlEnableConfigServerEnableDiscoveryClient主程序添加和啟動(dòng),訪

15、問(wèn)測(cè)試config 客戶端pom.xml 添加 config 客戶端依賴(lài)在四個(gè)項(xiàng)目中添加 bootstrap.yml啟動(dòng)服務(wù),觀察從配置中心獲取配置信息的日志配置刷新pom.xmlyml 配置文件中暴露 refresh 端點(diǎn)重啟服務(wù),查看暴露的刷新端點(diǎn)RefreshScopeUserServiceImpl 添加注解先啟動(dòng) user-service,再修改 config項(xiàng)目的user-service-dev.yml文件并提交訪問(wèn)刷新端點(diǎn)刷新配置訪問(wèn) user-service,查看動(dòng)態(tài)更新的新用戶數(shù)據(jù)二十四、config bus + rabbitmq 消息總線配置刷新rabbitmq 安裝筆記需要

16、動(dòng)態(tài)更新配置的微服務(wù),添加 spring cloud bus 依賴(lài),并添加 rabbitmq 連接信息pom.xml 添加 spring cloud bus 依賴(lài)配置文件中添加 rabbitmq 連接信息config-server 添加 spring cloud bus 依賴(lài)、配置rabbitmq連接信息,并暴露 bus- refresh 監(jiān)控端點(diǎn)pom.xmlapplication.yml啟動(dòng)服務(wù),請(qǐng)求刷新端點(diǎn)發(fā)布刷新消息config 本地文系統(tǒng)把配置文件保存到 sp12-config 項(xiàng)目的 resources/config 目錄下修改 application.yml 激活 native

17、profile,并指定配置文件目錄二十五、sleuth 鏈路跟蹤微服務(wù)中添加 spring cloud sleuth 依賴(lài)在控制臺(tái)查看鏈路跟蹤日志二十六、sleuth + zipkin 鏈路分析鏈路數(shù)據(jù)抽樣比例zipkin 服務(wù)下載 zipkin 服務(wù)器啟動(dòng) zipkin 時(shí),連接到 rabbitmq 微服務(wù)添加 zipkin 起步依賴(lài)啟動(dòng)并訪問(wèn)服務(wù),訪問(wèn) zipkin 查看鏈路分析spring cloud 介紹spring cloud 是一系列框架的集合。它利用 spring boot 的開(kāi)發(fā)便利性巧妙地簡(jiǎn)化了分布式系統(tǒng)基礎(chǔ)設(shè)施的開(kāi)發(fā),如服務(wù)發(fā)現(xiàn)注冊(cè)、配置中心、消息總線、負(fù)載均衡、斷路器、數(shù)

18、據(jù)監(jiān)控等,都可以用spring boot 的開(kāi)發(fā)風(fēng)格做到一鍵啟動(dòng)和部署。spring cloud 并沒(méi)有重復(fù)制造輪子,它只是將目前各家公司開(kāi)發(fā)的比較成熟、經(jīng)得起實(shí)際考驗(yàn)的服務(wù)框架組合起來(lái),通過(guò) spring boot 風(fēng)格進(jìn)行再封裝屏蔽掉了復(fù)雜的配置和實(shí)現(xiàn)原理,最終給開(kāi)發(fā)者留出了一套簡(jiǎn)單易懂、易部署和易維護(hù)的分布式系統(tǒng)開(kāi)發(fā)工具包。spring cloud 對(duì)于中小型互聯(lián)網(wǎng)公司來(lái)說(shuō)是一種福音,因?yàn)檫@類(lèi)公司往往沒(méi)有實(shí)力或者沒(méi)有足夠的資金投入去開(kāi)發(fā)自己的分布式系統(tǒng)基礎(chǔ)設(shè)施,使用 spring cloud 一站式解決方案能在從容應(yīng)對(duì)業(yè)務(wù)發(fā)展的同時(shí)大大減少開(kāi)發(fā)成本。同時(shí),隨著近幾年微服務(wù)架構(gòu)和 dock

19、er 容器概念的火爆,也會(huì)讓spring cloud 在未來(lái)越來(lái)越“云”化的軟件開(kāi)發(fā)風(fēng)格中立有一席之地,尤其是在目前五花八門(mén)的分布式解決方案中提供了標(biāo)準(zhǔn)化的、一站式的技術(shù)方案,意義可能會(huì)堪比當(dāng)年 servlet 規(guī)范的誕生,有效推進(jìn)服務(wù)端軟件系統(tǒng)技術(shù)水平的進(jìn)步。spring cloud 技術(shù)組成eureka微服務(wù)治理,服務(wù)注冊(cè)和發(fā)現(xiàn)ribbon負(fù)載均衡、請(qǐng)求重試hystrix斷路器,服務(wù)降級(jí)、熔斷feignribbon + hystrix 集成,并提供生命式客戶端hystrix dashboard 和 turbine hystrix 微服務(wù)監(jiān)控zuulAPI 網(wǎng)關(guān),提供微服務(wù)的統(tǒng)一入口,并提供

20、統(tǒng)一的權(quán)限驗(yàn)證config 配置中心bus消息總線, 配置刷新sleuth+zipkin 鏈路跟蹤Spring Cloud 對(duì)比 DubboDubboDubbo只是一個(gè)遠(yuǎn)程調(diào)用(RPC)框架默認(rèn)基于長(zhǎng)連接,支持多種序列化格式Spring Cloud 框架集提供了一整套微服務(wù)解決方案(全家桶)一、service - 服務(wù)spring cloud商品服務(wù) item service,端口 8001 用戶服務(wù) user service,端口 8101 訂單服務(wù) order service,端口 8201二、commons 通用項(xiàng)目返回目錄新建 maven 項(xiàng)目返回目錄pom.xml4.0.0com.t

21、edusp01commons0.0.1SNAPSHOTsp01commonscom.fasterxml.jackson.modulejacksonmoduleparameternames2.9.8com.fasterxml.jackson.datatypejacksondatatypejdk82.9.8com.fasterxml.jackson.datatypejacksondatatypejsr3102.9.8com.fasterxml.jackson.datatypejacksondatatypeguava2.9.8jectlomboklombok1.18.6javax.servletja

22、vax.servletapi3.1.0org.slf4jslf4japi1.7.26monscommonslang33.9org.apache.maven.pluginsmavencompilerplugin3.8.01.81.8java 源文件pojoItempackage com.tedu.sp01.pojo;import lombok.AllArgsConstructor; import lombok.Data;import lombok.NoArgsConstructor;Data NoArgsConstructor AllArgsConstructor public class It

23、em private Integer id; private String name; private Integer number;Userpackage com.tedu.sp01.pojo;import lombok.AllArgsConstructor; import lombok.Data;import lombok.NoArgsConstructor;Data NoArgsConstructorAllArgsConstructor public class User private Integer id; private String username; private Strin

24、g password;Orderpackage com.tedu.sp01.pojo; import java.util.List;import lombok.AllArgsConstructor; import lombok.Data;import lombok.NoArgsConstructor;Data NoArgsConstructor AllArgsConstructor public class Order private String id; private User user; private List items;serviceItemServicepackage com.t

25、edu.sp01.service; import java.util.List;import com.tedu.sp01.pojo.Item;public interface ItemService List getItems(String orderId);void decreaseNumbers(List list);UserServicepackage com.tedu.sp01.service; import com.tedu.sp01.pojo.User; public interface UserService User getUser(Integer id);void addSc

26、ore(Integer id, Integer score);OrderServicepackage com.tedu.sp01.service;import com.tedu.sp01.pojo.Order;public interface OrderService Order getOrder(String orderId); void addOrder(Order order);utilCookieUtilpackage com.tedu.web.util;import javax.servlet.http.Cookie;import javax.servlet.http.HttpSer

27、vletRequest; import javax.servlet.http.HttpServletResponse;public class CookieUtil /*param responseparam nameparam valueparam maxAge*/public static void setCookie(HttpServletResponse response,String name, String value, String domain, String path, int maxAge) Cookie cookie = new Cookie(name, value);i

28、f(domain != null) cookie.setDomain(domain);cookie.setPath(path); cookie.setMaxAge(maxAge); response.addCookie(cookie);public static void setCookie(HttpServletResponse response, String name, String value, int maxAge) setCookie(response, name, value, null, /, maxAge);public static void setCookie(HttpS

29、ervletResponse response, String name, String value)setCookie(response, name, value, null, /, 3600);public static void setCookie(HttpServletResponse response, String name) setCookie(response, name, , null, /, 3600);/*param requestparam namereturn*/public static String getCookie(HttpServletRequest req

30、uest, String name) String value = null;Cookie cookies = request.getCookies(); if (null != cookies) for (Cookie cookie : cookies) if (cookie.getName().equals(name) value = cookie.getValue();return value;/*param responseparam namereturn*/public static void removeCookie(HttpServletResponse response, St

31、ring name, String domain, String path) setCookie(response, name, , domain, path, 0);JsonUtilpackage com.tedu.web.util;import java.io.File; import java.io.FileWriter;import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Writer;import java.math.BigDec

32、imal; import java.math.BigInteger; import .URL;import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat;import java.util.ArrayList; import java.util.List;import mons.lang3.StringUtils;import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonGenera

33、tor; import com.fasterxml.jackson.core.JsonParser;import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference;import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.

34、databind.ObjectMapper;import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.datatype.guava.GuavaModule; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTi

35、meModule;import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; import lombok.extern.slf4j.Slf4j;Slf4jpublic class JsonUtil private static ObjectMapper mapper;private static JsonInclude.Include DEFAULT_PROPERTY_INCLUSION = JsonInclude.Include.NON_DEFAULT;private static boolean IS_ENABL

36、E_INDENT_OUTPUT = false; private static String CSV_DEFAULT_COLUMN_SEPARATOR = ,; static try initMapper(); configPropertyInclusion(); configIndentOutput(); configCommon(); catch (Exception e) log.error(jackson config error, e);private static void initMapper() mapper = new ObjectMapper();private stati

37、c void configCommon() config(mapper);private static void configPropertyInclusion() mapper.setSerializationInclusion(DEFAULT_PROPERTY_INCLUSION);private static void configIndentOutput() mapper.configure(SerializationFeature.INDENT_OUTPUT, IS_ENABLE_INDENT_OUTPUT);private static void config(ObjectMapp

38、er objectMapper) objectMapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN); objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); objectMapper.enable(DeserializationFeature.FAIL_ON_READING_

39、DUP_TREE_KEY); objectMapper.enable(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);objectMapper.disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES); objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); obje

40、ctMapper.enable(JsonParser.Feature.ALLOW_COMMENTS); objectMapper.disable(JsonGenerator.Feature.ESCAPE_NON_ASCII); objectMapper.enable(JsonGenerator.Feature.IGNORE_UNKNOWN); objectMapper.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TI

41、MESTAMPS); objectMapper.setDateFormat(new SimpleDateFormat(yyyyMMdd HH:mm:ss); objectMapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); objectMapper.registerModule(new ParameterNamesModule(); objectMapper.registerModule(new Jdk8Module(); objectMapper.registerModule(new JavaTimeModule(); objectMa

42、pper.registerModule(new GuavaModule();public static void setSerializationInclusion(JsonInclude.Include inclusion) DEFAULT_PROPERTY_INCLUSION = inclusion;configPropertyInclusion();public static void setIndentOutput(boolean isEnable) IS_ENABLE_INDENT_OUTPUT = isEnable; configIndentOutput();public stat

43、ic V from(URL url, Class c) try return mapper.readValue(url, c); catch (IOException e) log.error(jackson from error, url: , type: , url.getPath(), c, e); return null;public static V from(InputStream inputStream, Class c) try return mapper.readValue(inputStream, c); catch (IOException e) log.error(ja

44、ckson from error, type: , c, e); return null;e);public static V from(File file, Class c) try return mapper.readValue(file, c); catch (IOException e) log.error(jackson from error, file path: , type: , file.getPath(), c,return null;e);public static V from(Object jsonObj, Class c) try return mapper.rea

45、dValue(jsonObj.toString(), c); catch (IOException e) log.error(jackson from error, json: , type: , jsonObj.toString(), c,return null;public static V from(String json, Class c) try return mapper.readValue(json, c); catch (IOException e) log.error(jackson from error, json: , type: , json, c, e); retur

46、n null;public static V from(URL url, TypeReference type) try return mapper.readValue(url, type); catch (IOException e) log.error(jackson from error, url: , type: , url.getPath(), type, e); return null;public static V from(InputStream inputStream, TypeReference type) try return mapper.readValue(input

47、Stream, type); catch (IOException e) log.error(jackson from error, type: , type, e); return null;public static V from(File file, TypeReference type) try return mapper.readValue(file, type); catch (IOException e) log.error(jackson from error, file path: , type: , file.getPath(),type, e);return null;e

48、);public static V from(Object jsonObj, TypeReference type) try return mapper.readValue(jsonObj.toString(), type); catch (IOException e) log.error(jackson from error, json: , type: , jsonObj.toString(), type,return null;public static V from(String json, TypeReference type) try return mapper.readValue

49、(json, type); catch (IOException e) log.error(jackson from error, json: , type: , json, type, e); return null;public static String to(List list) try return mapper.writeValueAsString(list); catch (JsonProcessingException e) log.error(jackson to error, obj: , list, e); return null;public static String

50、 to(V v) try return mapper.writeValueAsString(v); catch (JsonProcessingException e) log.error(jackson to error, obj: , v, e); return null;public static void toFile(String path, List list) try (Writer writer = new FileWriter(new File(path), true) mapper.writer().writeValues(writer).writeAll(list); wr

51、iter.flush(); catch (Exception e) log.error(jackson to file error, path: , list: , path, list, e);public static void toFile(String path, V v) try (Writer writer = new FileWriter(new File(path), true) mapper.writer().writeValues(writer).write(v); writer.flush(); catch (Exception e) log.error(jackson

52、to file error, path: , obj: , path, v, e);public static String getString(String json, String key) if (StringUtils.isEmpty(json) return null;try JsonNode node = mapper.readTree(json); if (null != node) return node.get(key).toString(); else return null; catch (IOException e) log.error(jackson get stri

53、ng error, json: , key: , json, key, e); return null;public static Integer getInt(String json, String key) if (StringUtils.isEmpty(json) return null;try JsonNode node = mapper.readTree(json); if (null != node) return node.get(key).intValue(); else return null; catch (IOException e) log.error(jackson

54、get int error, json: , key: , json, key, e); return null;public static Long getLong(String json, String key) if (StringUtils.isEmpty(json) return null;try JsonNode node = mapper.readTree(json); if (null != node) return node.get(key).longValue(); else return null; catch (IOException e) log.error(jack

55、son get long error, json: , key: , json, key, e); return null;public static Double getDouble(String json, String key) if (StringUtils.isEmpty(json) return null;try JsonNode node = mapper.readTree(json); if (null != node) return node.get(key).doubleValue(); else return null; catch (IOException e) log

56、.error(jackson get double error, json: , key: , json, key, e); return null;public static BigInteger getBigInteger(String json, String key) if (StringUtils.isEmpty(json) return new BigInteger(String.valueOf(0.00);try JsonNode node = mapper.readTree(json); if (null != node) return node.get(key).bigInt

57、egerValue(); else return null; catch (IOException e) log.error(jackson get biginteger error, json: , key: , json, key, e); return null;public static BigDecimal getBigDecimal(String json, String key) if (StringUtils.isEmpty(json) return null;try JsonNode node = mapper.readTree(json); if (null != node

58、) return node.get(key).decimalValue(); else return null; catch (IOException e) log.error(jackson get bigdecimal error, json: , key: , json, key, e); return null;public static boolean getBoolean(String json, String key) if (StringUtils.isEmpty(json) return false;try JsonNode node = mapper.readTree(js

59、on); if (null != node) return node.get(key).booleanValue(); else return false; catch (IOException e) log.error(jackson get boolean error, json: , key: , json, key, e); return false;public static byte getByte(String json, String key) if (StringUtils.isEmpty(json) return null;try JsonNode node = mappe

60、r.readTree(json); if (null != node) return node.get(key).binaryValue(); else return null; catch (IOException e) log.error(jackson get byte error, json: , key: , json, key, e); return null;public static ArrayList getList(String json, String key) if (StringUtils.isEmpty(json) return null;String string

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論