当前位置: 首页 > 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.huolong8.cn/news/418120/

相关文章:

  • 自己做淘客网站成本大吗要想提高网站排名应该如何做
  • 网络小说写作网站查询收录
  • 怎么面试一个网站开发的人创建网站超市
  • 挂马网站现象wordpress网站主题插件
  • 做网站那家好深圳网络优化
  • 上海建设房屋网站志勋网站建设公司
  • 什么网站用vue做的广告电话
  • 展架立式落地式seo搜索引擎优化怎么做
  • 深圳罗湖区住房和建设局网站网站建设公司不给ftp
  • 长沙营销型网站设计针对315老坛酸菜企业解决方案
  • 做外贸需要用什么网站专业制作开发公司网站
  • 北京互联网网站建设做a漫画在线观看网站
  • 烟台网站seo无锡互联网企业
  • 建设银联官方网站dede 中英文网站
  • 基于php技术的小型企业网站开发wordpress移除工具栏
  • php网站模板下载做母婴产品的网站
  • 千助网站建设找人做彩票网站多少钱
  • 做请帖网站自己做服务器的网站吗
  • net网站开发网络建设方式
  • 乌市昌吉州建设局网站wordpress 下载类型
  • 郑州定制网站推广工具产品上海滕州建设集团网站
  • php商城网站开发报告商铺门面设计
  • 完成网站建设企业标识
  • 做学校网站的内容aso关键词覆盖优化
  • 服装购物网站策划书交换友情链接的途径有哪些
  • 做国际网站需要多少钱旅游网站排名查询
  • 如何免费建网站赚钱用手机怎么申请免费自助网站
  • 广东专业网站优化制作公司网络营销推广的形式
  • 如何评价企业网站推广效果?安徽安庆旅游必去十大景点
  • 做关于什么的网站网站开发南京招聘