小编men*_*.ye的帖子

为什么Spring框架不赞成使用Guava缓存?

我想使用带有番石榴缓存的spring-cache,但我发现guava缓存已被春季官方文档标记为已弃用.我想知道为什么,他们没有给出一些解释.

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html#boot-features-caching-provider-guava

spring guava spring-boot

18
推荐指数
1
解决办法
9697
查看次数

更新数据库后如何更新redis?

我在redis中缓存一些数据,如果存在则从redis读取数据,否则从数据库读取数据并以redis形式写入数据.

我发现更新数据库后有几种方法可以更新redis.例如:

  1. 将redis中的密钥设置为已过期
  2. 更新datebase后立即更新redis.
  3. 将数据放入MQ并使用consumer来更新redis.

我有点困惑,不知道如何选择.

你能告诉我每种方式的优缺点吗,最好告诉我更新redis的其他方法或推荐一些关于这个问题的博客.

database caching redis

11
推荐指数
1
解决办法
1万
查看次数

为什么父类中的@PostConstruct方法在子类中的@PostConstruct方法之后执行?

我对下面代码的结果有点困惑.
ParentController:

@Controller
public abstract class ParentController{

@PostConstruct
public void init(){
    System.out.println("Parent-----PostConstruct");
}


public ParentController(){
    System.out.println("Parent-----constructor");
}
} 
Run Code Online (Sandbox Code Playgroud)

ChildController:

@Controller
public class ChildController extends ParentController {
 @PostConstruct
public void init() {
    System.out.println("Child-----PostConstruct");
}

public ChildController(){
    System.out.println("Child-----constructor");
}
}
Run Code Online (Sandbox Code Playgroud)

结果如下:
Parent ----- constructor
Child ----- constructor
Child ----- PostConstruct
Parent ----- PostConstruct

我不知道为什么parent的postConstruct是在child的postContruct之后.

java spring annotations

9
推荐指数
1
解决办法
3818
查看次数

spring数据如何根据方法名生成sql?

我知道spring数据jpa可以通过两种方式执行sql.一个是执行sql,它包含在@Query中,另一个是解析方法名称并生成sql.我从github克隆了spring数据jpa的源代码,想找出spring数据如何根据方法名生成sql.但是我找不到与解析方法名相关的类.所以,你能告诉我一些关于如何spring data jpa是关于解析方法名称的吗?谢谢

spring-data spring-data-jpa

6
推荐指数
1
解决办法
796
查看次数

如何通过mybatis基于注释将对象(超过10个属性)插入mysql而不列出所有属性

我想通过mybatis基于注解将一个具有10多个属性的Object插入到mysql中。但我必须列出所有属性,这太不方便了。我想知道是否有一些方法可以轻松插入对象,而无需通过 mybatis 列出所有属性。这是我的片段。多谢。

@Insert("insert into poi_shop(name,brand,tags,status,phone,mobile,business_time,address,city,lng,lat,business_type,attribute_json) values(#{name},#{brand},#{tags},#{status},#{phone},#{mobile},#{business_time},#{address},#{city},#{lng},#{lat},#{business_type},#{attribute_json})")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
public Long insertPoiInfo(PoiBo poiBo);
Run Code Online (Sandbox Code Playgroud)

java mysql annotations mybatis spring-mybatis

2
推荐指数
1
解决办法
2094
查看次数

Mysql唯一键不起作用

这是我的桌子:

CREATE TABLE `loan_table` (
 `ID` bigint(38) NOT NULL AUTO_INCREMENT,
 `LOAN_ID` bigint(38) DEFAULT NULL,
 `PLAN_ID` bigint(38) NOT NULL,
 `EXT_LOAN_APP_ID` bigint(38) DEFAULT NULL,
 `REDISTRIBUTE_TIME` datetime DEFAULT NULL,
 PRIMARY KEY (`ID`),
 UNIQUE KEY `IDX_UN_LOAN_PLAN_APP`(`LOAN_ID`,`PLAN_ID`,`EXT_LOAN_APP_ID`,`REDISTRIBUTE_TIME`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
Run Code Online (Sandbox Code Playgroud)

我在 4 列(LOAN_ID、PLAN_ID、EXT_LOAN_APP_ID、REDISTRIBUTE_TIME)上添加唯一键,但我可以一次又一次地执行下面的插入 SQL。

INSERT INTO `loan_table` (`LOAN_ID`, `PLAN_ID`,`EXT_LOAN_APP_ID`, `REDISTRIBUTE_TIME`)
VALUES
( 435870, 0,  2369, NULL);
Run Code Online (Sandbox Code Playgroud)

mysql

2
推荐指数
1
解决办法
1282
查看次数