• spring boot——参数传递——URL后面接参数:示例:?username=1221&age=12——通过Bean对象来获取前端页面参数


    创建Bean对象:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    package com.awaimai.web;
     
    public class Student
    {
        private String firstName;
        private String lastName;
     
        public void setFirstName(String firstName)
        {
            this.firstName = firstName;
        }
     
        public String getFirstName()
        {
            return firstName;
        }
     
        public void setLastName(String lastName)
        {
            this.lastName = lastName;
        }
     
        public String getLastName()
        {
            return lastName;
        }
     
    }

    控制器:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    package com.awaimai.web;
     
    import org.springframework.web.bind.annotation.*;
     
    @RestController
    public class kzq
    {
     
        @RequestMapping(value = "/test2")
        public String test2(Student student)
        {
            String a = student.getFirstName();
            String b = student.getLastName();
            return a+b;
        }
     
    }

    web访问:

    ==================================================================

        // http://localhost:8080/test291?firstName=zhangsi&lastName=wanGwu
    
        //  zhangsiwanGwu
    
        @RequestMapping(value = "/test291")
        public String test281(Student student)
        {
            String a = student.getFirstName();
            String b = student.getLastName();
            return a+b;
        }
    

      

    package com.bulunzhihao.web;
    
    public class Student
    {
        private String firstName;
        private String lastName;
    
        public void setFirstName(String firstName)
        {
            this.firstName = firstName;
        }
    
        public String getFirstName()
        {
            return firstName;
        }
    
        public void setLastName(String lastName)
        {
            this.lastName = lastName;
        }
    
        public String getLastName()
        {
            return lastName;
        }
    
    }
    

      

    http://localhost:8080/test291?firstName=zhangsi&lastName=wanGwu

    ---------------------------------------------------------------------------------------------------------------------------------------

  • 相关阅读:
    Python 生成器
    Python 装饰器
    Go语言【第十四篇】:Go语言基础总结
    Go语言【第十三篇】:Go语言递归函数
    Go语言【第十二篇】:Go数据结构之:切片(Slice)、范围(Range)、集合(Map)
    Go语言【第十一篇】:Go数据结构之:结构体
    Java入门之:对象和类
    Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 04
    Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 03
    Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 02
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/16102171.html
Copyright © 2020-2023  润新知