
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
👁️ 阅读量:0
© 版权声明:本文《Spring MVC @RequestAttribute注解》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686619190a307203.html。