测试开发进阶——spring boot——MVC——post访问——使用@RequestParam获取参数

web网页post提交数据:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
 <form action="http://localhost:8080/test2" method="POST">
     <p>username <input type = "text" name = "username" /></p>
     <p>password <input type = "text" name = "password" /></p>
     <p><input type = "submit" value = "submit" /></p>
  </form>
</body>
</html>

  

控制器:

package com.awaimai.web;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class kzq
{

    @RequestMapping(value = "/test2")
    public String test2(@RequestParam("username") String username,@RequestParam("password") String password)
    {
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        return "success";

    }

}

  

web访问:

 

原文地址:https://www.cnblogs.com/xiaobaibailongma/p/15086986.html