springboot webflux 参数传递(表单传递)


springboot webflux 参数传递(表单传递)

 

表单传递的参数可使用注解(@RequestParam)读取,也可使用路由函数处理

 

 

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

注解:@RequestParam

 

@RestController
public class HelloController {

    @RequestMapping("/get2")
    public String hello2(@RequestParam String name){
        System.out.println("name:"+name);

        return name;
    }

    @RequestMapping("/get3")
    public String hello3(ServerWebExchange exchange){
        String name=exchange.getRequest().getQueryParams().getFirst("name");
        System.out.println("name:"+name);

        return name;
    }

    @RequestMapping("/get4")
    public Mono<String> hello4(ServerHttpRequest request){
        String name=request.getQueryParams().getFirst("name");
        System.out.println("name:"+name);

        assert name != null;
        return Mono.just(name);
    }
}

 

 

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

路由函数

 

public class CustomRouterConfig {

    @Bean
    public RouterFunction<ServerResponse> initRouterFunction(){
        return RouterFunctions.route()
                .POST("/hello2",serverRequest -> {
                    String name=serverRequest.exchange().getRequest().getQueryParams().getFirst("name");
                    System.out.println("name:"+name);

                    assert name != null;
                    return ServerResponse.ok().bodyValue(name);
                })
                .build();
    }
}

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值