Home » Java » Spring MVC citation development memorandum

Spring MVC citation development memorandum

Spring MVC development
memo notes


Spring MVC development

memo notes


This article is not

Spirng MVC to explain, you can own Google.

related articles


First look at the

Spring MVC notes in the development of commonly used tags, as shown in the following table:

























































number



notes



The location of



note



1



@Controller



will become the Spring Bean

class

class



stage @Controller, @Service, @Repository and @Component function is equivalent to

notes

2



@RequestMapping



request

mapping

,



refers to the annotation class class implements the Controller interface


labeling method in extended Spring predefined Controller means (such as: SimpleFormController

)

3



@RequestParam



URL

bound to the Senate

.

specifies the URL parameters and the method to the Senate binding rules



4



@SessionAttributes



Session set the range of properties



class



Such as:

@SessionAttributes ("user"), the user ModelMap attribute is added to the Session range of



5



@InitBinder



Controller registered custom property editor



method



Methods

@InitBinder notes must have a type of WebDataBinder in ginseng, so that the Spring MVC framework will register the Attribute Editor for the WebDataBinder object is passed to



6



@ModelAttribute



prepared to use data / bind the ModelMap property to the

.

method in parameter



tagging in method: ready reference data


tagging in to the Senate: the property binding in ModelMap to request processing method in reference




look into the parameter types in Controller method:































































number



The

request processing method into the optional

.



1



Java basic data types and String



by default by name, mode of binding to URL parameters, can change the default binding @RequestParam annotation rules



2



request/response/session



can be both Servlet and API can also be Portlet API corresponding to Spring, they will be bound to the corresponding object Servlet and Portlet container



3



org.springframework.web.context.request.WebRequest



contains an internal request object



4



java.io.InputStream/java.io.Reader



can access the contents of the request



5



java.io.OutputStream / java.io.Writer



can take the operation of response



6



Any

marked the @RequestParam annotation in



labeled @RequestParam annotations into the Senate is bound to the request specific parameters on.



7



java.util.Map / org.springframework.ui.ModelMap



Model potential request

binding Spring MVC framework which each have created, they can be the Web view object access (such as JSP)



8



The

command / form object (object note: commonly known URL binding parameters using HTTP GET to send the command object, and that parameter URL binding uses HTTP POST sent to the form object)



they attribute binding rules to match the name to the URL parameters, and complete the type conversion. The type conversion rules can be adjusted by

or @InitBinder annotation of the HandlerAdapter configuration

9



org.springframework.validation.Errors / org.springframework.validation.BindingResult



check result attribute list commands / form objects, pay attention to test results of parameters must be close behind the

command / form objects

10



rg.springframework.web.bind.support.SessionStatus



can use this type of status object explicitly end form, this is equivalent to removing the session trigger defined by the

property @SessionAttributes


look at the return type of the Controller method:
































number



The

request processing method into the optional

.



1



void



The logical view corresponding to the name

by request processing method URL, method as the following:


@RequestMapping ("/welcome.do")


public void welcomeHandler ({

)

}


The logical view of the corresponding

named "welcome"



2



String



the logical view called returning characters, methods such as the following:



@RequestMapping (method = RequestMethod.GET)


public String setupForm (@RequestParam ("ownerId") int ownerId, ModelMap model {

)

Owner owner = this.clinic.loadOwner (ownerId);


model.addAttribute (owner);


return "ownerForm";


}



The logical view of the corresponding

named "ownerForm"



3



org.springframework.ui.ModelMap



and the return type of void, the logical view depends on the corresponding request Natori URL, such as the following:



@RequestMapping ("/vets.do")


public ModelMap vetsHandler ({

)

return new ModelMap (this.clinic.getVets) (

);

}



The logical view of the corresponding

named "vets", ModelMap will be returned as a model object request corresponding to the access to the.

page in the JSP view

4



org.springframework.web.servlet.ModelAndView



Of course,

can also be a traditional ModelAndView.



Latest