Summary of the first week of November

1. Sometimes the query is slow, because the query result may require the splicing of the results of the two interfaces. In this case, you can use the asynchronous method to improve the query speed.

Example:

        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("执行主线程");

A more concise way:

        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. Functional programming Function and BiFunction interface

public interface Function<T, R> One parameter T, one return result R

public interface BiFunction<T, U, R> Two parameters are T, U respectively, one returns the result R

3. GET requests and POST requests contain arrays and lists

1) The parameters of the GET request can also use a list

    @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) The post method parameter is an array

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

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

3) The post method is a list

First case:

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

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

4) Non-standard writing method of POST method ( in doubt, this method is not a standard post method, it can also be used )

    @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);

Second case:

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

 

4. Read the spring-mvc framework written by others and record the main steps

1) Scan all classes of a specific package, use the class name on the class as the key, and the class instance as the value, which is stored in the Map ioc

2) Traverse the map of the ioc, take the url in the method in the class as the key, use the method as the value, store it in the Map handlerMapping, use the url as the key, and the class instance as the value, and store it in the Map controllerMap

3) The parameter types of the request are HttpServletRequest and HttpServletResponse. According to HttpServletRequest, the request parameters and request url can be obtained. According to the request url, the request method can be obtained from the handlerMapping, and the class instance can be obtained from the controllMap. With parameters, methods, and class instances, reflection can be used. way to call.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324178784&siteId=291194637