admin管理员组文章数量:1794759
Spring MVC @RequestAttribute注解
@RequestAttribute
获取HTTP的请求(request)对象属性值,用来传递给控制器的参数。
创建Hello控制器
package com.controller; import org.Springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class Hello { @RequestMapping("/show") public String show(@RequestAttribute("name")String userName) { System.out.println("userName="+userName); return "success"; } }创建index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>index</title> </head> <body> <% request.setAttribute("name", "baixue"); request.getRequestDispatcher("/show").forward(request,response); %> </body> </html>启动 Tomcat访问 index.jsp
本文标签: 注解springMVCRequestAttribute
版权声明:本文标题:Spring MVC @RequestAttribute注解 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686618970a86967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论