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

广州企业网站建设哪家好建个短视频网站

广州企业网站建设哪家好,建个短视频网站,做一个网站要什么样技术,大型网站怎么加载图片的在 Spring Boot 2 项目中配置时间格式#xff0c;通常可以通过配置文件#xff08;application.properties 或 application.yml#xff09;或者通过 Java 代码进行配置。以下是两种常见的配置方式#xff1a; 1. 通过配置文件配置时间格式#xff1a; 在 application.pr…在 Spring Boot 2 项目中配置时间格式通常可以通过配置文件application.properties 或 application.yml或者通过 Java 代码进行配置。以下是两种常见的配置方式 1. 通过配置文件配置时间格式 在 application.properties 或 application.yml 文件中添加配置项指定全局的时间格式 # 使用 application.properties 文件 spring.jackson.date-formatyyyy-MM-dd HH:mm:ss或者使用 YAML 格式 # 使用 application.yml 文件 spring:jackson:date-format: yyyy-MM-dd HH:mm:ss这样配置后Spring Boot 将使用指定的时间格式序列化日期时间对象。 2. 通过 Java 代码配置时间格式 在 Java 代码中配置你可以创建一个配置类继承 WebMvcConfigurerAdapter在 Spring Boot 2 中WebMvcConfigurerAdapter 已被废弃可以直接实现 WebMvcConfigurer 接口 import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.time.format.DateTimeFormatter;Configuration public class WebMvcConfig implements WebMvcConfigurer {Overridepublic void addFormatters(FormatterRegistry registry) {// 配置全局日期时间格式registry.addFormatter(new DateFormatter(yyyy-MM-dd HH:mm:ss));} }上述代码中addFormatters 方法用于注册自定义的格式化器这里使用 DateFormatter 配置全局的日期时间格式。 选择其中一种方式进行配置即可具体取决于你的偏好和项目的需求。这样配置后Spring Boot 将按照指定的日期时间格式将日期时间对象转换为字符串并响应给前端。 请给个完整的示例 包含控制层 pojo 当你想要在 Spring Boot 2 中配置全局的时间格式可以按照以下示例进行操作。 创建一个 POJO 类 // ExamplePojo.java import java.time.LocalDateTime;public class ExamplePojo {private String name;private LocalDateTime dateTime;// 省略构造函数、getter 和 setter 方法 }创建控制层类 // ExampleController.java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import java.time.LocalDateTime;RestController RequestMapping(/api) public class ExampleController {GetMapping(/example)public ExamplePojo getExample() {ExamplePojo examplePojo new ExamplePojo();examplePojo.setName(Example);examplePojo.setDateTime(LocalDateTime.now());return examplePojo;} }创建一个全局的日期时间格式配置类 // DateTimeConfig.java import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;import java.time.format.DateTimeFormatter;Configuration public class DateTimeConfig implements WebMvcConfigurer {Overridepublic void addFormatters(FormatterRegistry registry) {// 配置全局日期时间格式registry.addFormatter(new LocalDateTimeFormatter(yyyy-MM-dd HH:mm:ss));}private static class LocalDateTimeFormatter implements org.springframework.format.FormatterLocalDateTime {private final DateTimeFormatter formatter;LocalDateTimeFormatter(String pattern) {this.formatter DateTimeFormatter.ofPattern(pattern);}Overridepublic LocalDateTime parse(String text, java.util.Locale locale) {return LocalDateTime.parse(text, formatter);}Overridepublic String print(LocalDateTime object, java.util.Locale locale) {return formatter.format(object);}} }在这个配置类中LocalDateTimeFormatter 类实现了 Formatter 接口用于将 LocalDateTime 对象转换为字符串并在 addFormatters 方法中注册该格式化器。 启动你的 Spring Boot 应用程序然后访问 /api/example你将得到如下响应 {name: Example,dateTime: 2022-12-25 15:30:00 }这样你就成功地配置了全局的日期时间格式。请注意这里的时间格式化是基于 LocalDateTime 对象的如果你的实际情况中使用了其他的日期时间类型可能需要稍作修改。
http://www.yutouwan.com/news/418120/

相关文章:

  • 网站建设合同审批公司网站建设多少钱需要
  • 福州网站建设哪家强微信小程序与网站连接
  • 麦积区城乡建设局网站wordpress 站中站
  • 四川建设网官方网站wordpress静态化配置
  • 天津企业建站系统慈溪电商网站建设公司
  • 深圳建设交易信息网站wordpress社区插件
  • 深圳网站建设龙华新科洛阳网站搭建
  • dw网站建设的数据库中国肩章
  • 大庆市城乡建设局网站首页如何做网站的优化
  • 网站建设廴金手指花总壹柒织梦cms怎么安装
  • 建设网站的拓扑图濮阳网站关键词
  • 案例学 网页设计与网站建设网站建设先做后
  • 网站的建设需要多少钱phpcms和帝国cms哪个好
  • 商会信息平台网站建设方案微信公众号创建要钱吗
  • 鞍山云网站做网站的空间需要买吗
  • 专业微网站开发上海平面网站
  • 计算机网络技术网站开发做条形图的网站
  • 网站前端和后台免费空间建网站
  • 旅游网站开发的流程图公司形象墙设计效果图
  • 安徽工程建设造价信息网站个人门户网站备案
  • 网站美工工作流程凡科送审平台官网
  • 口腔医院网站建设wordpress模板开发文档
  • 简述网站开发主要步骤wordpress wiki知识库
  • 网站项目规划与设计西安网站建设外包
  • 上海定制网站建设推广微信scrm系统
  • 网站开发东莞用php做一网站有哪些
  • 做站群什么样的算是违法网站发布新闻的平台有哪些
  • 襄阳市住房城乡建设部网站1核1g可以做几个网站
  • 门户网站建设整改措施简单动画制作软件
  • 百度指数官网太原seo排名公司