SpringMVC简单注解的意思
package org.springmvc.learn.controller;
import java.util.Map;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
*
* @author a666sh
*
*/
@RestController
@RequestMapping("/hello")
public class HelloWorldController {
/**
*
* @RestController 指定controller类
* @RequestMapping 指定url映射路径
* @RequestParam 指定该参数为视图层传过来的参数(如果不使用该注解也可以通过参数传参,
* 该参数默认required为true,修改为false可以使其不是必须)
* @PathVariable 该注解可以获取url中的路径作为参数获得,可以用来实现restful风格
* 如下,通过该注解可以获取/hello/home/{id}中的{id}值,且该值指定为Integer的
*/
@RequestMapping(value="home/{id}",method=RequestMethod.GET)
public String home(Map<String,Object> model,Model model02,@RequestParam(required=false) String username,
@PathVariable Integer id) {
model.put("hello", "good boy");
System.out.println(username);
System.out.println(id);
model02.addAttribute("world", "bad boy!");
return "home";
}
/**
* SpringMVC传值到view层,可以通过在方法中传递一个Map<String,Object>参数,并将值设置进去map
* 也可以通过SpringMVC提供的Model对象作为参数,并通过该参数的addAttribute方法传值,推荐使用Model传值
* 总结:SpringMVC的url映射和值的传递非常清晰明了,将参数的获取和视图的返回简化起来,使得controller可以专注于
* 业务逻辑的处理
*/
}