11月第一周小结

1.有时候查询比较慢,因为查询结果可能需要两个接口的结果的拼接,此时可以使用异步的方式提高查询速度

举例:

        CompletableFuture future = supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "返回接口1的结果 ";
        });
        CompletableFuture future2 = supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "返回接口2的结果";
        });

        System.out.println(future.get());
        System.out.println(future2.get());
        System.out.println("执行主线程");

更加简洁的方式:

        CompletableFuture<String> combine = CompletableFuture.supplyAsync(()->{
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "firstTask";
        }).thenCombine(CompletableFuture.supplyAsync(() -> {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return "SecondTask";
                }), (s1, s2) -> {
                    return s1 + s2;
                });
        System.out.println(combine.get());

2.函数式编程Function和BiFunction接口

public interface Function<T, R>     一个参数T , 一个返回结果R

public interface BiFunction<T, U, R>  两个参数分别为T, U,一个返回结果R

3.GET请求和POST请求中含有数组和列表的情况

1)GET请求的参数也可以使用列表

    @GET
    @Path("/order-settlement/list")
    PageableResponse<BizOrderSettlementModel> queryOrderSettlement(@QueryParam("pageNum") int pageNum,
                                                                   @QueryParam("pageSize") int pageSize,
                                                                   @ApiParam("业务线") @QueryParam("businessLine") List<String> businessLines,
                                                                   @ApiParam("省份") @QueryParam("province") String province,
                                                                   @ApiParam("资金方名称") @QueryParam("fundingPartyName") String fundingPartyName);

2)post方式参数是数组

    @POST
    @Path("/stop/msg")
    boolean stopCollectionInfo(StopCollectionVo request);
@Data
public class StopCollectionVo {

    //授信id
    private String appId;
    //停催手段
    private String[] stopChannel;
}

3)post方式是列表

第一种情形:

    @POST
    @Path("/stop/msg")
    boolean stopCollectionInfo(StopCollectionVo request);
@Data
public class StopCollectionVo {

    //授信id
    private String appId;
    //停催手段
    private List<String> stopChannel;
}

4)POST方式非标准写法(存在疑问,这种方式不是标准的post方式,也可以使用)

    @POST
    @Path("/orders-for-settlement")
    Map<String, List<OrderSettleOutModel>> getTcSettleInfoModels(@QueryParam("biz-line") @DefaultValue("TIANCHENG") String businessLine,
                                                                   @QueryParam("start-date") Long startDate, @QueryParam("end-date") Long endDate);

第二种情形:

    @POST
    @Path("/deduct/security")
    @ApiOperation("扣除保证金")
    DecuctSecurityModel decuctSecurity(@NotEmpty List<DecuctSecurityRequest> decuctSecurityVos);

 

4.阅读别人写的spring-mvc框架,记录主要步骤

1)扫描特定包的所有类,将类上类名作为key,类实例作为value,存在Map ioc中

2) 遍历该ioc的Map,取类中的方法中的url作为key,将方法作为value,存入Map handlerMapping中,将url作为key,类实例作为value,存入Map controllerMap中

3)请求的参数类型HttpServletRequest和HttpServletResponse,根据HttpServletRequest可以得到请求参数和请求url,根据请求url可以从handlerMapping中获取请求方法,从controllMap中获取类实例,有了参数,方法,类实例,可以通过反射的方式调用。

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值