In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to achieve springboot date format processing and default jump home page". In daily operation, I believe many people have doubts about how to achieve springboot date format processing and default jump home page. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer "how to achieve springboot date format processing and default jump home page". Next, please follow the editor to study!
Package com.example.airquality.conf;import org.apache.commons.lang3.StringUtils;import org.springframework.core.convert.converter.Converter;import org.springframework.stereotype.Component;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.List / * * @ author Han Zhilong * configuration file, formatting the input time of the entire project in the WebMvcCongig class using * @ version 1.0 * @ description: TODO * @ date 2021-5-21 9:56 * / @ Componentpublic class DateConverterConfig implements Converter {private static final List formarts = new ArrayList (4); private static final String YYYY_MM = "yyyy-MM"; private static final String YYYY_MM_DD = "yyyy-MM-dd" Private static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm"; private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; static {formarts.add (YYYY_MM); formarts.add (YYYY_MM_DD); formarts.add (YYYY_MM_DD_HH_MM); formarts.add (YYYY_MM_DD_HH_MM_SS) } @ Override public Date convert (String source) {if (StringUtils.isBlank (source)) {return null;} source = source.trim (); if (source.matches ("^\\ d {4} -\ d {1d2} $")) {return parseDate (source, formarts.get (0)) } else if (source.matches ("^\\ d {4} -\ d {1Magne2} -\\ d {1jin2} $") {return parseDate (source, formarts.get (1)) } else if (source.matches ("^\\ d {4} -\ d {1 formarts.get 2} -\\ d {1} 2}:\\ d {1J 2}:\) {return parseDate (source, formarts.get (2)) } else if (source.matches ("^\\ d {4} -\ d {1else if 2} {1}\ d {1Power2}:\\ d {1Power2}:\) {return parseDate (source, formarts.get (3));} else {throw new IllegalArgumentException (" Invalid false value'"+ source +")) }} / * formatted date * @ param dateStr String character date * @ param format String format * @ return Date date * / private Date parseDate (String dateStr, String format) {Date date; try {DateFormat dateFormat = new SimpleDateFormat (format); date = dateFormat.parse (dateStr) } catch (Exception e) {throw new IllegalArgumentException (e.getLocalizedMessage ());} return date;}} package com.example.airquality.conf;import org.springframework.context.annotation.Configuration;import org.springframework.core.Ordered;import org.springframework.format.FormatterRegistry;import org.springframework.web.servlet.config.annotation.* @ Configurationpublic class WebMvcConfig extends WebMvcConfigurationSupport {@ Override public void addViewControllers (ViewControllerRegistry registry) {registry.addViewController ("/"). SetViewName ("redirect:/qualityIndex/toFindAll"); registry.setOrder (Ordered.HIGHEST_PRECEDENCE); super.addViewControllers (registry);} / * * add custom Converters and Formatters. * / @ Override protected void addFormatters (FormatterRegistry registry) {registry.addConverter (new DateConverterConfig ());} / * if WebMvcConfigurationSupport is inherited, the relevant content configured in yml will become invalid. Need to reassign static resource * * @ param registry * / @ Override public void addResourceHandlers (ResourceHandlerRegistry registry) {registry.addResourceHandler ("/ * *") .addResourceLocations ("classpath:/static/") .ad dResourceLocations ("classpath:/resources/") .addResourceLocations ("classpath:/META-INF/resources/"); super.addResourceHandlers (registry) At this point, the study on "how to implement springboot date format processing and default jump to the home page" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.