To simplify the SPRINGMVC configuration, spring also introduces the MVC namespace, which configures theSpring will register a requestmappinghandlermapping, a requestmappinghandleradapter, and an exceptionhandlerexceptionresolver by default Three beans to support the processing of requests by a controller decorated with annotations (@RequestMapping, @ExceptionHandler, @Controller, etc.). The following features are also available: 1, Spring 3 style type conversion through a Conversionservice insta
a full article, so we won't dwell on its details in this article, but focus on the many new classes introduced in the new Java.time package, such as Localdate, LocalTime, and LocalDateTime.Spring has a Data transformation framework that allows strings and Java data types to be converted to each other. Spring 4 Upgrades The transformation framework to support those classes in the Java 8th and time API. So your code can write this:@RestControllerpublic class Examplecontroller { @RequestMapping (
I. Dependencies to be used in the introduction of projects Two. Create an entity class Public classAir {PrivateInteger ID; PrivateString District; @DateTimeFormat (Pattern="YYYY-MM-DD Hh:mm:ss") @JsonSerialize (using= Jsondateserializer.class) PrivateDate Monitortime; PrivateInteger PM10; PrivateInteger PM25; PrivateString monitoringstation; PrivateDate CreateDate; PublicInteger getId () {returnID; } Public voidsetId (Integer id) { This. ID =I
Data processing includes:1. Data type Conversion2. Data type formatting3. Data validation.1). How to verify? Annotations?①. Using the JSR 303 validation Standard②. Add jar Package for Hibernate validator Validation Framework③. Add ④. Need to add corresponding annotations on the Bean's properties⑤. Adding @Valid annotations before the target method bean type2). Verify that the error is turning to which page?Note: The Bean object that needs to be validated and its bound result object or Error obje
seriously read you, leave your valuable comments or suggestions, so you, me, and everyone faster and better common progress!All right, let's cut to the chase!Method One: Add date formatting annotations in entity classes@DateTimeFormat (pattern = "YYYY-MM-DD") private Date receiveapptime;As above, on the corresponding attributes, plus the specified date format of the annotations, I personally tested, easy to solve the problem!Method Two: Add a data bi
System.out.println (User.tostring ()); System.out.println (DD); return "index"; }16}Above, problem solved. Then we switch the second way, delete the Basecontroller class, add annotations directly to the CreateDate field in the user entity class, and note the 10th line of code: 1 Import java.util.Date; 2 3 Import Org.springframework.format.annotation.DateTimeFormat; 4 5 public class User {6 7 private int userId; 8 private String UserName; 9 @
Annotation checksums are dependent on javax.validation and Hibernate-validaton.Dependency> groupId>Javax.validationgroupId> Artifactid>Validation-apiArtifactid> version>1.1.0.Finalversion>Dependency>Dependency> groupId>Org.hibernategroupId> Artifactid>Hibernate-validatorArtifactid> version>5.0.1.Finalversion>Dependency>To activate the note driver for spring:/>Define the data model: Public classSubscriber {@Size (min=2, max=30) PrivateString name; @NotEmpty @EmailPrivateStri
Title, Ajax requests to get JSON data to populate the HTML page, encountered a time cannot format the problem.Because it is JS, the FMT tag reference is invalid, the web also searched many JS time formatted functions are invalid.Since spring MVC was used to think of annotations, the way to do this is to use annotations on the application's Entity class Time field:@DateTimeFormat (pattern = "YYYY-MM-DD hh:mm:ss")//annotations can inject time in this fo
system will be formatted into the ISO date standard, but the actual use of most of the use of the process may be yyyy-mm-dd or YYYY-MM-DD HH:mm:ss Two formats of the date, The workaround is to change the datetime type to a string type itself, and then serialize it. If you do not want to modify the code, you can implement the following scenario.Json.NET provides a isodatetimeconverter date conversion class that can be jsnconverter to achieve the appropriate date conversion [Jsonconverter (typ
1, unified JSON format processing mode, while specifying the contenttype type, to resolve the low version of the browser to get JSON contenttype to Application/json prompted to download the problem. Public Abstract classCustomresult: ActionResult { Public Abstracttdata GetObject (); protectedjsonserializersettings serializersettings; protected voidinitserialization (ControllerContext context) {Httpresponsebase response=context. Httpcontext.response; Response. ContentType="text/html";
System.DayOfWeek.Tuesday:Case System.DayOfWeek.Wednesday:Case System.DayOfWeek.Friday:mm=mm+1;Break}}return mm;}
Get a valid weekday between any two dates (excluding weeks 6th) get a valid weekday between any two dates (excluding weeks 6th) #region Get a valid weekday between any two dates (excluding week 6th)
CallDateTime date1=convert.todatetime ("2005-10-20");DateTime date2=convert.todatetime ("2005-11-01");int days =getdays (DATE1,DATE2);private int getdays (System.DateTime date1,system.dat
(Timeinmillis);
Create a DateTime object using Java.util.Date
Java.util.Date jdkdate = Obtaindatesomehow ();
datetime = new DateTime (jdkdate);
Create a DateTime object directly with different objects
Use a calendar
Java.util.Calendar calendar = obtaincalendarsomehow ();
datetime = new DateTime (calendar);
Use another Joda datetime
datetime anotherdatetime = Obtaindatetimesomehow ();
datetime = new DateTime (anotherdatetime);
Use a String (must is formatted properly)
/Note that if you
Can be manually configured instead of this shorthand form, which allows beginners to quickly apply the default configuration scheme.
and provides: data binding support,@NumberFormatannotation Support,@DateTimeFormat Support,@Valid support, read-write XML support (JAXB),Read and write JSON support (Jackson).
Support for JSON is used when processing response to Ajax requests.When you write JUnit unit tests on the action, you complete the test by fet
In Springmvc, types such as date,double are defined in the bean, and the date and double cannot be bound without any processing.
The solution is to use the @initbinder tag provided by spring MVC
In my project, you add method Initbinder to the Basecontroller and use annotations @initbinder annotations, so spring MVC registers these editors before binding the form, and of course if you're not bothered, You can also write it individually in each of your controller. The rest of the controllers inhe
Defines a static class that defines a static method in which the parameter type is preceded by the This modifier to implement a method extension to the parameter type
Examples for example
namespace demo{//The class here must be static class public static class Json {//method is static method//This modifier is a string type that extends the Tojson method for string type
public static Object Tojson (this string json) {return Json = = null? Null:JsonConvert.DeserializeObject (Json);} The
Spring MVC Form Processing Example The following example illustrates how to write a simple web-based application that leverages the HTML forms that use the Spring Web MVC framework.
A test project to build
(1) Create a new Java Web project and introduce the jar packages needed for several SPRINGMVC projects, the project structure and the required jar packages as follows:
①web.xml:
This defines the URL suffix for SPRINGMVC interception with an. HTML end and handles it
②springmvc-se
Author=#{author,jdbctype=varchar} A if>
- ifTest= "Publishdate!=null">
- and Publish_date=#{publishdate,jdbctype=timestamp} the if>
- where>
- Select>
Add in Bookmapper.java:
List
Join in Bookdao
1 Public List selectbycondition (book book) {
2 return Bookmapper.selectbycondition (book);
3 }
Join in Bookservice
1 Public List selectbycondition (String bookname, string auth
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.