Spring MVC formats data by adding custom annotations

Spring MVC custom annotations and parsing of custom annotations

1、 Custom annotation name

2、 Test class

3、 Parse the package where the test class is located and reflect

Encountered a problem

The start time and end time are imported into the interface in the format of yyyymmdd. It is required that the queried data must be filtered with a given time period.

such as

However, after the server accepts the time, according to the business requirements, the format should be

Stime can use the @ datetimeformat (pattern = "yyyymmdd") provided by spring MVC by default to get the correct start time, but the default format annotation cannot meet the requirements for the end time~

Follow @ datetimeformat custom interface

Because it is imitated, some methods that can be used are inherited without major changes.

@Mydatetimeformat annotation

@Mydatetimeformat annotation processing class

Overload parse interface

By calling the original handler function super Parse (text, locale), get the converted Date object, then add relevant processing business, and then return date.

Register our custom annotation handling class with spring MVC

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>