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

深圳企业网站建设费用明细深圳龙岗网站制作

深圳企业网站建设费用明细,深圳龙岗网站制作,加盟装修公司怎么合作,深圳市福田区公司一. 场景描述 在进行前后端交互时#xff0c;发现实体的LocalDateTime返回的格式是这样的#xff1a; 这不符合我们日常习惯的格式 “年-月-日 时:分:秒”#xff0c;于是上网学习了前辈 励碼的文章SSM项目中LocalDateTime格式化最佳实践_localdatetime 格式化-CSDN博客解决…一. 场景描述 在进行前后端交互时发现实体的LocalDateTime返回的格式是这样的 这不符合我们日常习惯的格式 “年-月-日 时:分:秒”于是上网学习了前辈 励碼的文章SSM项目中LocalDateTime格式化最佳实践_localdatetime 格式化-CSDN博客解决了问题。 二. 解决方案 用到的和 jackson 相关的依赖有 !-- Json序列化ObjectMapper -- dependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion2.18.1/version /dependency !--用于适配JAVA的时间类型比如LocalDateTime-- !-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310 -- dependencygroupIdcom.fasterxml.jackson.datatype/groupId artifactIdjackson-datatype-jsr310/artifactIdversion2.18.2/version /dependency 2.1 创建配置类 千万别忘了注册 JavaTimeModule()否则会报错转换不了 LocalDateTime类型 /*** author yamu* version 1.0* description 配置响应的 Json 字符串的时间格式* date 2025/1/24 9:54*/ Configuration public class JacksonConfig {public static final String DEFAULT_DATETIME_FORMAT yyyy-MM-dd HH:mm:ss;public static final String DEFAULT_DATE_FORMAT yyyy-MM-dd;public static final String DEFAULT_TIME_FORMAT HH:mm:ss;Bean(name myObjectMapper)public ObjectMapper myObjectMapper() {ObjectMapper objectMapper new ObjectMapper();//适用于java8的时间模块JavaTimeModule javaTimeModule new JavaTimeModule();//年-月-日 时:分:秒DateTimeFormatter localDateTimeFormatter DateTimeFormatter.ofPattern(DEFAULT_DATETIME_FORMAT);javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(localDateTimeFormatter));javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(localDateTimeFormatter));//年-月-日DateTimeFormatter dateFormatter DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(dateFormatter));javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(dateFormatter));//时:分:秒DateTimeFormatter timeFormatter DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT);javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(timeFormatter));javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(timeFormatter));//注册时间模块(不注册的话会报错Java 8 date/time type java.time.LocalDateTime not supported by default: add Module com.fasterxml.jackson.datatype:jackson-datatype-jsr310 to enable handling... )objectMapper.registerModule(javaTimeModule);// 配置其他特性objectMapper.setTimeZone(TimeZone.getTimeZone(GMT8));//设置东八区return objectMapper;} } 2.2 在响应类中注册 这里有个注意点由于我的响应类是通过R.success(T)去返回给前端的所以自定义的ObjectMapper需要静态注入但是Autowired是不支持自动静态注入的所以我定义了一个工具类去进行注入。 /*** description: 自定义消息响应类* author yamu* date 2024/11/12 11:22* version 1.0*/ Data public class RT {private Integer code; //0失败1成功private String message; //错误信息private T data; //数据public static ObjectMapper objectMapper;//静态代码块注入JacksonConfig定义的objectMapperstatic{objectMapper ObjectMapperUtil.getObjectMapper();}/*** description: 带返回值成功* param: object* returns: RT* author yamu* date: 2024/11/12 11:24*/public static T String success(T object) {RT r new RT();r.data object;r.code 1;try {return objectMapper.writeValueAsString(r);} catch (JsonProcessingException e) {throw new RuntimeException(e);}} }2.3 定义工具类静态注入ObjectMapper /*** author yamu* version 1.0* description 获取自定义序列化器的 ObjectMapper* date 2025/1/24 17:06*/ Component public class ObjectMapperUtil implements ApplicationContextAware {private static ApplicationContext context;Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {context applicationContext;}public static ObjectMapper getObjectMapper() {return (ObjectMapper) context.getBean(myObjectMapper);} } public static ObjectMapper getObjectMapper() {return (ObjectMapper) context.getBean(myObjectMapper);} } 结果如下
http://www.w-s-a.com/news/653643/

相关文章:

  • 校园网站建设招标公告php网站开发什么
  • 06628 网页制作与网站开发陕西省交通建设网站
  • 做wish如何利用数据网站暗红色网站
  • 企业 网站备案 法人长春建站模板搭建
  • 网站做快照网站改版 升级的目的
  • 自己做一个网站要多少钱海外推广什么意思
  • 郑州做网站哪家专业网络基础知识大全
  • 济南制作网站企业php 调试网站
  • 互联网站管理工作细则做网站通栏模糊
  • 徐州手机网站开发公司电话青岛有名的互联网公司
  • 如何在手机做网站wordpress 网站搬迁
  • 网站透明导航代码国外卖货平台有哪些
  • 张家界网站建设方案中国网页设计师
  • 淮南网站建设服务东莞营销型手机网站建设
  • 常德做网站专业公司河南高端网站建设
  • 网站服务器建设的三种方法会展设计ppt
  • 如何把自己做的网站放到内网seo优化网络
  • 北京网站建设net2006厦门优化公司
  • 制作网页前为什么要建立站点菏泽百度网站建设
  • 做影视网站引流网页美工设计课程教案
  • 响应式网站开发流程图网站优化seo教程
  • 做汽车团购网站百度官网平台
  • 网站增加关键字建设旅游网站的功能定位
  • 怎么搭建源码网站义乌网络
  • 定远规划建设局网站wordpress云主机安装
  • 慈溪市网站开发软件开发文档国家标准
  • 本地佛山顺德网站设计公司的网站如何建设
  • 网站建设前十名网站建设 招标书
  • 手机网站标准百度搜索关键词排名优化推广
  • 中国空间站科幻作文1000字wordpress运行库