springboot 参数传递(表单传递)


springboot 参数传递(表单传递)

 

 

***************************

相关注解

 

@Requestparam

@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestParam {
    @AliasFor("name")
    String value() default "";

    @AliasFor("value")
    String name() default "";  //参数的名称

    boolean required() default true; //是否需要该参数

    String defaultValue() default "\n\t\t\n\t\t\n\ue000\ue001\ue002\n\t\t\t\t\n";
}

 

 

***************************

示例

 

*****************

pojo 层

 

Person

@Data
public class Person {

    private String name;
    private Integer age;
}

 

*****************

controller 层

 

HelloController

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello(String name,Integer age){  //可直接用使用表单对应的参数接受数据
        System.out.println(name+"  "+age);

        return name+"  "+age;
    }

    @RequestMapping("/hello2")
    public String hello2(Person person){  //用pojo接受数据
        System.out.println(person);

        return person.toString();
    }
}

 

*****************

前端页面

 

<body>
<form th:action="@{/hello}" th:align="center">
    name:<input name="name"><br>
    age :<input name="age"><br>
    <button>提交</button>
</form>
</body>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SpringBoot中,常用的参数的绑定方式包括路径参数、查询参数、请求体参数以及表单数据参数。路径参数是通过在URL路径中定义占位符来传递参数,可以使用@PathVariable注解进行绑定。查询参数是通过URL中的查询字符串传递参数,可以使用@RequestParam注解进行绑定。请求体参数是通过请求体中的数据传递参数,可以使用@RequestBody注解进行绑定。表单数据参数是通过表单提交的数据传递参数,可以使用@RequestParam注解或者MultipartFile类型进行绑定。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [SpringBoot前后端参数传递方式总结](https://blog.csdn.net/liuerchong/article/details/112425692)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [教你4招优雅实现Spring Boot 异步线程间的数据传递](https://blog.csdn.net/Java_LingFeng/article/details/128543461)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值