Spring MVC使用 package orc.dhw.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframewor
package orc.dhw.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.portlet.ModelAndView; import orc.dhw.bean.UserInfo; @Controller @RequestMapping("/user") public class UserInfoController { @RequestMapping(value="/test4") public ModelAndView test4(){ ModelAndView mo = new ModelAndView(); mo.addObject(new UserInfo(1001, "刘德华", "123", 1)); return mo; } @RequestMapping(value="/test1/{id}/{name}") public String test1(@PathVariable("id")String id,@PathVariable("name")String name){ System.out.println("有人访问我"+id); System.out.println("有人访问我"+name); return "index"; } @RequestMapping(value="/test2") public String test2(UserInfo info){ System.out.println(info); return "index"; } @RequestMapping(value="/ajax",produces="text/plain;charset=utf-8") @ResponseBody public String ajax(String name,String pwd){ System.out.println(name); System.out.println(pwd); return "这是AJAX请求"; } @RequestMapping(value="/test3") public String test3(@RequestParam(value="abc",required=false,defaultValue="aaaaa")String id){ System.out.println(id); return "index"; } }