Three methods for spring MVC to obtain parameters -- Idea

01? 2022-02-13 07:30:06 阅读数:362

methods spring mvc obtain parameters

1、 build springMVC frame , If you don't know, you can click the article on my home page

2、 Create one to forward to the default page and jump to the controller TestControler
```
package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TestController {


// Forward to by default test_param.html page
    @RequestMapping("/")
    public String Param(){
        return "test_param";
    }

}
```
3、 Create the corresponding html page
```
<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title> Test request parameters </title>
</head>
<body>

<h1> Request parameters </h1><br/>

<a th:href="@{/testServletAPI(username='admin',password='123456')}"> test servletAPI Get request parameters </a><br/>
<a th:href="@{/testParam(username='admin',password='123456')}"> Get request parameters for test controller formal parameters </a><br/>

<form th:action="@{/testParam}" method="post">
    user name :<input type="text" name="user_name"><br/>
    password :<input type="text" name="password"><br/>
    hobby :<input type="checkbox" name="hobby" value="a">a
    <input type="checkbox" name="hobby" value="b">b
    <input type="checkbox" name="hobby" value="c">c
    <input type="submit" value=" The controller gets the parameters ">
</form><br/>

<form th:action="@{/testpojo}" method="post">
    user name :<input type="text" name="username"><br>
    password :<input type="password" name="password"><br>
    Gender :<input type="radio" name="sex" value=" male "> male
    <input type="radio" name="sex" value=" Woman "> Woman <br>
    Age :<input type="text" name="age"><br>
    mailbox :<input type="text" name="email"><br>
    <input type="submit" value=" Use pojo Receiving parameters ">
</form>

</body>
</html>

copyright:author[01?],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130730045276.html