zoukankan      html  css  js  c++  java
  • @RequestParam--SpringMVC 注解系列文章(一)

    • 概述

      RequestParam 注解是使用 SpringMVC 开发过程中,比较常用的一个注解,用于映射请求参数。

    • 代码
    package rex.springmvc.handlers;
    
    import org.apache.log4j.Logger;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    
    @RequestMapping(value="/requestParamTest")
    @Controller
    public class RequestParamTest {
    	private static final Logger logger = Logger.getLogger(RequestParamTest.class);
    	private static final String SUCCESS = "success";
    
    	/**
    	 * @RequestParam 注解可以用来映射请求参数
    	 * value 值即为请求参数名称
    	 * required 表示请求参数是否允许为空,默认值是true
    	 * defaultValue 值为请求参数的默认值
    	 *
    	 * @param userNm
    	 * @param age
    	 * @return
    	 */
    	@RequestMapping(value="/testRequestParam", method=RequestMethod.GET)
    	public String testRequestParam(@RequestParam(value="userNm") String userNm,
    			@RequestParam(value="age", required=false, defaultValue="0") int age){
    		logger.debug("userNm:" + userNm);
    		logger.debug("age:" + age);
    		return SUCCESS;
    	}
    }
    

      

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>ReqeustParam Test</title>
    </head>
    <body>
        <a href="requestParamTest/testRequestParam?userNm=RexFang&age=18">ReqeustParam Test</a>
    </body>
    </html>

    欢迎转载,转载必须标明出处

  • 相关阅读:
    iis日志时间与本地日期不一样
    iis原理介绍
    IIS如何确定请求的处理程序
    handle 和module
    调试IIS服务器
    JS面向对象学习
    图片垂直居中大杂烩
    淘宝双十一页面(Flexible)
    用rem适配移动端
    About getByClass
  • 原文地址:https://www.cnblogs.com/rexfang/p/6592525.html
Copyright © 2011-2022 走看看