Project structure:The field of time in a database datetime1. Database design2. addnews.jsppageencoding=" Utf-8 "%>cssclass=" Wdate " Onfocus= "Wdatepicker ({skin: ' Whygreen ', datefmt: ' Yyyy-mm-dd HH:mm:ss '});" Name= "Newstime" size= "value=" "/>The control used to insert the time: My97datepicker http://www.my97.net/index.asp, can also be downloaded here3. News.javaImportjava.io.Serializable;Importjava.util.Date;ImportOrg.springframework.format.annotation.DateTimeFormat;//News Public classNew
data
Add the Birthday (birthday) input box to the form, and in the JavaBean Brith property, the type of the property is Java.util.Date
Page 400 error when submitting form, data cannot be submitted to target method
Cause: The birthday of the input box is not formatted
Workaround:annotation on the birth property of the JavaBean object@DateTimeFormat (pattern = "Yy-mm-dd"private Date birth;①, date formatting@
, to solve this problem, we can derive a new class, rewrite the ExecuteResult method, and use Json.net to complete serialization, JsonResultPro. the code for the cs file is as follows:
Namespace JSONDateMVC. common {using System; using System. web; using System. web. mvc; using Newtonsoft. json; using Newtonsoft. json. converters; public class JsonResultPro: JsonResult {public JsonResultPro () {} public JsonResultPro (object data, JsonRequestBehavior behavior) {base. data = data; base. jsonReque
Json.NET to complete the serialization work, the code for the JsonResultPro.cs file is as follows:namespace jsondatemvc.common{using System; Using System.Web; Using SYSTEM.WEB.MVC; Using Newtonsoft.json; Using Newtonsoft.Json.Converters; public class Jsonresultpro:jsonresult {public Jsonresultpro () {} public Jsonresultpro (object data, Json Requestbehavior behavior) {base. data = data; Base. Jsonrequestbehavior = behavior; This.
Numberformatannotationformatterfactory implementsannotationformatterfactoryTo trigger formatting, simply add the @numberformat annotation to the field:public class MyModel {@NumberFormat (style=style.currency) private BigDecimal decimal;}Formatting Annotations APIThe Org.springframework.format.annocation package contains a handy formatting annotation API. Use @numberformat to format the Java.lang.Number field. Use @datetimeformat to format the Java.u
Bookcrudcontroller class, the code is as follows:/** * Add Book Data * * @param title Book title * @param author book author * @param wordCount book Words * @param publishdate release time * @ return */@PostMapping ("/add/book/novel") public responseentity Add (@RequestParam ("title") String title, @RequestParam ("author") String author, @RequestParam ("Word_count") int wordCount, @RequestParam ("Publish_date") @
JDK8 's Localdate series Date API is a lot more useful than date or Calendar, but there's a little problem with automatic assembly in SPRINGMVC.Causes a similar exception to be throwndefault for the property ' CreateDate '; for value ' 2017-11-03 ';ForWorkaround 1 Note @DateTimeFormat (pattern = "Yyyy-mm-dd HH:mm:ss") the date that the form or URL passes through must be strictly based on this format, there is no need to complete the front end of the
What does 17.15 Configuring Spring MVC says It also performs the following actions:
1. Spring 3 style conversion through a Conversionservice instance in addition to the JavaBeans Propertyeditors used F or Data Binding.
2. Support for formatting number fields using the @NumberFormat annotation the through.
3. Support for formatting Date, Calendar, Long, and Joda time fields using the @DateTimeFormat annotation.
4. Support for validating @Controller inp
Foreground to background Java when data date type conversion, Java to database data date format conversion
Foreground to Java:
Entity class with @datetimeformat so that is the passing of the empty string can also be transferred to the same format as the previous pass
@XmlElement (name = "Begindate")
@DateTimeFormat (pattern = "YYYYMMDD")
Private Date begindate;
End Date
@XmlElement (name = "EndDate")
@
Today in the spring official demo to see the Joda-time, so go to Joda-time official website to understand a bit, instantly by its powerful function and ease of use of the admiration. Joda-time Introduction
joda-time-Alternative selection of date/Time libraries for Java applications, Joda-time makes time and date values easier to manage, manipulate, and understand. In fact, easy to use is the main design goal of Joda. Other goals include scalability, a complete set of features, and support for mu
Are the personal understanding of SPRINGMVC;
@DateTimeFormat (pattern= "Yyyy-mm-dd HH:mm:ss")@JsonFormat (pattern= "Yyyy-mm-dd HH:mm:ss", timezone = "gmt+8")
1 parsing/formatting of the field level
Add @DateTimeFormat (pattern= "Yyyy-mm-dd HH:mm:ss") to the attribute or get method of the entity class.
The date string in the form is correctly converted to the date type. There are also @numberformat annotati
If all the time in an entity class, that is, a datetime type field, is processed into a uniform format, you can use the following method:New Isodatetimeconverter (); " YYYY-MM-DD HH:mm:ss " ; Jsonconvert.serializeobject (Stu, Newtonsoft.Json.Formatting.Indented, TimeFormat);If you need to return the format is inconsistent, such as some need month and day, some days and seconds, then this control. You can define properties to resolve1 Public classStudent2 {3
1. Configure Annotation-driven >mvc:annotation-driven>2. Add annotations such as @numberforma on the entity class @NumberFormat (pattern= "#,###,###.#") private Float price; @DateTimeFormat (Pattern= "Yyyy-mm-dd") private Date productiondate;That's it.Data formatting* Format the input and output of the Property object, which is still in the category of "type conversion" in nature* Spring defines an implementation of the Conversionservice
for ibatis custom log service is generated for the first three adaptation factories; For log4netloggerfa in ibatisnet. Common. Logging. impl, it is mainly used to generate ilog implementation for log4net Log Service adaptation. Let's take a look at the implementation of leleoutloggerfa.
Public ilog getlogger (type){Return getlogger (type. fullname );}Public ilog getlogger (string name){// Slightly modify the cacheIlog log = new consoleoutlogger (name, _ level, _ showdatetime, _ showlogname,Ret
;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;//Will hand this class to the spring IOC container management@Controller Public classHellocontroller {//URI@RequestMapping ("/helloworld") PublicString Hello () {///web-inf/page/success.jsp return"Success"; } @RequestMapping ("/test") PublicString Test () {return"Success"; }}The configuration file will be returned by the method of character channeling automatic stitching a
When it comes to web development, the page passes in a string type, and SPRINGMVC can convert some of the basic types, but the conversion to the date class may require us to configure.1, if the query class lets us write ourselves, then adds the @DateTimeFormat (pattern = "Yyyy-mm-dd") before the property, can convert the string to the date type, as follows @DateTimeFormat (pattern = "YYYY-MM-DD") private D
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.