Synchronous and asynchronous request Request

Return Value Type synchronization request:

void: Han did not return

String: represents a logical view name

ModelAndView: The object is both logical view name, you can also carry data to the page you want to show

 

Sync requests: how to carry data controller layer onto the page.

    1. ModelAndView as the return value type

    2. Use Map, Model, ModelMap, the type of the value parameter in the front page you can use el expressions

  Note: Regardless ModelAndView or placed Map, springmvc in the underlying data will put hair request domain

From the value of the domain

$ {Username} gamut find the default domain from the smallest to find pageScope -> requestScope -> sessionScope -> ApplicationScope.

${requestScope.username} 

@RequestMapping("testResponse")
public ModelAndView testResponse(){
ModelAndView mv = new ModelAndView("result")
Book book
= new Book(); book.setBookName ( "alive" ); book.setPrice(89); mv.addObject ( "Books" , Book);
// insert the data can also be called the database data
return mv; }

2.Map types of parameters. When used to return a value of type String

@RequestMapping("testResponse")
public String testResponse(Map<String,Object> map){
map.put("userName", "张三");
return  "result";
}
 // out of the box with el expression in the front page

When using the same parameters and the use of 3.Model ModelMap to use the return value of type String

@RequestMapping("testResponse")
public String testResponse(Model model){
model.addAttribute("username","张三");
return  "result";

}

 

 

Asynchronous request: Ajax

Guess you like

Origin www.cnblogs.com/ych961107/p/11888368.html