注意:此文章是个人原创,希望有转载需要的朋友们标明文章出处,如果各位朋友们觉得写的还好,就给个赞哈,你的鼓励是我创作的最大动力,LinusZhu在此表示十分感谢,当然文章中如有纰漏,请联系linuszhu@163.com,敬请朋友们斧正,谢谢。
这一部分比较简单,所以直接上代码,详见注释部分:
package com.spring.controller; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.SessionAttributes; @Controller @RequestMapping("/user.do") public class UserController { @RequestMapping(params="method=reg4") public String reg4(ModelMap map) { System.out.println("Controller.reg4()"); //return "forward:index.jsp"; //forward默认可以不写 //return "forward:user.do?method=reg5"; //转发到另一方法 //return "redirect:user.do?method=reg5"; //重定向到另一方法 return "redirect:http://www.csdn.net/"; //重定向到url } @RequestMapping(params="method=reg5") public String reg5(String uname,ModelMap map) { System.out.println("Controller.reg5()"); System.out.println(uname); return "index.jsp"; } } |