1. 设置google pay订阅商品
  2. 设置google cloud project,并关联到Google pay
  3. https://juejin.cn/post/7376532114106236979
  4. 配置主题的pub/sub publisher
  5. google-play-developer-notifications@system.gserviceaccount.com
  6. 创收设置

得到HttpServletRequest的三种方式
方式一:Controller方法参数
在Controller的方法参数上写上HttpServletRequest,这样每次请求过来得到就是对应的HttpServletRequest。

@GetMapping(“/test”)
public void test(HttpServletRequest request) {}
方式二:从RequestContextHolder上下文获取
@GetMapping(“/test”)
public void test(HttpServletRequest request) {
// 从请求上下文里获取Request对象
ServletRequestAttributes requestAttributes = ServletRequestAttributes.class.
cast(RequestContextHolder.getRequestAttributes());
HttpServletRequest contextRequest = requestAttributes.getRequest();

}
方式三:依赖注入@Autowired
@Autowired
HttpServletRequest req;

@GetMapping(“/test”)
public void test(HttpServletRequest request) {}

原文:https://blog.csdn.net/hzau_itdog/article/details/108851270

Exception in thread “main” java.lang.NullPointerException
at java.util.HashMap.merge(HashMap.java:1225)
at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1320)
at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.ex.demo2.user.Test.main(Test.java:25)

@Data
public class Product {
    private Integer id;
    private String name;
    private String sex;
}

public class Test {
    public static void main(String[] args) {
        List<Product> products = new ArrayList<Product>();
        for (int i = 0; i < 3; i++) {
            Product product = new Product();
            product.setId(i + 1);
            product.setName(String.format("name_%s", i));
            product.setSex(i % 2 == 0 ? "MAN" : "WOMAN");
            products.add(product);
        }
//这里把第二个product的name设为null
        products.get(1).setName(null);
        Map<Integer, String> collect = products.stream().collect(Collectors.toMap(Product::getId,Product::getName));
        System.out.println(collect);
}

这里可以看到如果toMap的value是null的就会报空指针,经过测试 如果id为null也会报空指针

解决这个问题,可以通过filter过滤掉这些null的数据

     Map<Integer, String> collect = products.stream()
                .filter(k -> k.getId() != null).filter(v -> v.getName() != null)
.collect(Collectors.toMap(Product::getId, Product::getName));

等于:criteriaBuilder.equal

Predicate countryPredicate = criteriaBuilder.equal(root.get(“name”), “小明”);

and 和 or 查询

criteriaBuilder.and(predicates.toArray(Predicate对象,Predicate对象)

criteriaBuilder.or(predicates.toArray(Predicate对象,Predicate对象))

大于:criteriaBuilder.greaterThan

criteriaBuilder.greaterThan(root.get(“name”), 3);

小于:criteriaBuilder.lessThan

大于等于:criteriaBuilder.greaterThanOrEqualTo

小于等于:criteriaBuilder.lessThanOrEqualTo

相似查询:criteriaBuilder.like

Specification spec = (Specification) (root, criteriaQuery, criteriaBuilder) -> {

Predicate p = criteriaBuilder.like(root.get(“name”), “%” + “小明” + “%”);

return p;

};