请求参数的绑定


入门


1.params.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

    <%--请求参数绑定--%>
    <a href="param/testParam?username=hehe&password=123">请求参数的绑定</a>
</body>
</html>

2.paramcontroller

/**
 * 请求参数绑定
 */
@Controller
@RequestMapping("/param")
public class ParamController {

    /**
     * 请求参数绑定入门
     * @return
     */
    @RequestMapping("testParam")
    public String testParam(String username,String password){

        System.out.println("执行了...");
        System.out.println(username);
        System.out.println(password);
        return "success";
    }
}

请求参数绑定实体类型(封装到javaBean)


1.Account实体类

public class Account implements Serializable {
    private String username;
    private String password;
    private Double money;

    @Override
    public String toString() {
        return "Account{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", money=" + money +
                '}';
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Double getMoney() {
        return money;
    }

    public void setMoney(Double money) {
        this.money = money;
    }
}

2…paramas.jsp

<form action="param/saveAccount" method="post">
    姓名:<input type="text" name="username"/><br/>
    密码:<input type="text" name="password"/><br/>
    金额:<input type="text" name="money"/><br/>
         <input type="submit" value="提交"/>
</form
  1. ParamControlle

    /**
      * 请求参数绑定
      */
     @Controller
     @RequestMapping("/param")
     public class ParamController {
     
         /**
          * 把请求参数封装到javaBean的类中
          * @return
          */
         @RequestMapping("/saveAccount")
         public String testParam(Account account){
     
             System.out.println("执行了...");
             System.out.println(account);
             return "success";
         }
     }
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值