1.参数传递

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>传参测试页面</title>
</head>
<body>
<a th:href="@{/pt_text_zhanwei/admin/1}">占位符参数传递</a>
<a th:href="@{/pt_text_hs(username='damin',password=123456)}">参数传递(使用HttpServletRequest)</a>
<a th:href="@{/pt_text(username='damin',password=123456)}">参数传递(使用控制器形参)</a>
</body>
</html>
package com.sun.Controller;


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

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

@Controller
public class ParamTestController {


    //占位符传参
    @RequestMapping("pt_text_zhanwei/{name}/{pw}")
    public String t1(@PathVariable("name")String username,@PathVariable("pw")Integer password){

        System.out.println("账号: "+username+"-------密码: "+password);
        return "success";
    }


    //使用HttpServletRequest传递参数
    @RequestMapping("/pt_text_hs")
    public String t2(HttpServletRequest request){

        String name=request.getParameter("username");
        String pw=request.getParameter("password");
        System.out.println("账号: "+name+"-------密码: "+pw);
        return "success";
    }




    //使用控制器形参传递参数
    @RequestMapping("/pt_text")
    public String t3(String username,int password){


        System.out.println("账号: "+username+"-------密码: "+password);
        return "success";
    }



}

 

posted @ 2021-08-23 15:06  L1998  阅读(31)  评论(0)    收藏  举报