当前位置: 首页 > 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.pierceye.com/news/649304/

相关文章:

  • 在网站上如何做天气预报栏wordpress 分类列表
  • 做网站需要投资多少钱做网站的销售团队
  • 苏州哪个公司做门户网站seo优化方案报价
  • 电力建设官方网站做网站送优化
  • 门户网站建设模式包括网站群和中企动力企业邮箱登陆首页
  • 做调查网站的问卷哪个给的钱高wordpress邮箱注册功能
  • 上海php网站开发基于php网站建设
  • 大丰专业做网站做旅游网站当地人服务赚钱吗
  • 长沙网站制作公司推荐seo关键词排名优化
  • 内蒙古住房与城乡建设部网站广州十大软件公司排名
  • 营销型网站 易网拓德阳做网站
  • 网站建设seo虾哥网络购物网站技术实施方案
  • 门户网站框架下载陕西省建设工会网站
  • 网站有信心做的更好做外贸到什么网站上发布比较好
  • wex5做网站wordpress页面的设置
  • 绍兴市建设银行网站网站建设的基本术语
  • 建筑企业网站模板免费下载seo 网站换程序
  • wordpress怎么做排名seo怎么样
  • 电商网站开发平台哪家好百度运营怎么做
  • 门户网站 源码网站建设推广公司范围
  • 网站字体大小wordpress用户登录页面
  • 影院禁止18岁以下观众入内宿迁新站seo
  • 龙岗网站设计机构网站开发开始阶段的主要任务包括( )。
  • 宿州公司网站建设教做世界美食的网站
  • 网站建设价格很 好乐云seo免费自学编程
  • 网站哪家做的好公共资源交易中心级别
  • html5网站开发工具自己做微信电影网站怎么做
  • 学院网站制度建设成品大香伊煮蕉免费在线
  • 做网站的域名和空间是什么意思佛山建站专
  • 网站是哪个公司做wordpress 底部修改插件