1.idea启动时读不到其他配置文件中配置得属性
启动配置中选Build Project
2.@ConfigurationProperties初始化时读不到配置文件中的值
原因:我把属性写在了application-cache.yml文件中,但是没有把cache标签加到application.yml文件中
解决办法
3.pd生成ddl
1.多个表同时生成ddl
2.单个表得ddl
4.枚举类或者其他value类型得返回try catch
public class EmployeeCacheConfiguration {
/**
* 时间
*/
Long time;
/**
* 单位
*/
String timeUnit;
public TimeUnit getTimeUnit(){
try{
return TimeUnit.valueOf(timeUnit);
}catch (Exception e){
return TimeUnit.HOURS;
}
}
}
6.@SuperBuilder
@Builder
并不支持父类成员属性的构造,@SuperBuilder
注解的出现,就是用来解决这个问题。父类和子类上都加上@SuperBuilder,这样子类就可以正常获取到父类的成员属性进行builder构造了。
//子类
@SuperBuilder
@FieldDefaults(level = AccessLevel.PRIVATE,makeFinal = true)
public class InvoiceTypeTaxAggregate extends AbstractState
//父类
@Getter
@SuperBuilder
@FieldDefaults(level = AccessLevel.PROTECTED)
public abstract class AbstractState {
7.分享一段有文化的代码
我有一个实体,想获得yml文件中配置的信息,但是这个实体是不被spring管理的Bean。
解决思路,在调用这个实体时,把所需参数传入,并且是在调用者构造方法中初始化参数
@Slf4j
@FieldDefaults(level = AccessLevel.PRIVATE)
public class EmployeeCache {
Long time;
TimeUnit timeUnit;
/**
* personId为key 员工实体为value
*/
public final Cache<Long, Employee> personIdCache;
/**
* accountId为key 员工实体为value
*/
public final Cache<String, Employee> accountIdCache;
/**
* 在职人员信息缓存
*/
public final Cache<EmployeeId, com.ai.ep.domain.employee.Employee> hiredEmployeeCache;
/**
* 在职和离职人员信息缓存
*/
public final Cache<EmployeeId, com.ai.ep.domain.employee.Employee> hiredOrLeftEmployeeCache;
@Builder
public EmployeeCache(Long time,TimeUnit timeUnit){
this.time = time;
this.timeUnit = timeUnit;
personIdCache = Caffeine.newBuilder()
//存活时间十分钟
.expireAfterWrite(this.time, this.timeUnit)
.maximumSize(200)
.build();
accountIdCache = Caffeine.newBuilder()
//存活时间十分钟
.expireAfterWrite(this.time, this.timeUnit)
.maximumSize(200)
.build();
hiredEmployeeCache = Caffeine.newBuilder()
//存活时间十分钟
.expireAfterWrite(this.time, this.timeUnit)
.maximumSize(200)
.build();
hiredOrLeftEmployeeCache = Caffeine.newBuilder()
//存活时间十分钟
.expireAfterWrite(this.time, this.timeUnit)
.maximumSize(200)
.build();
}
}
@Service
@Slf4j
@FieldDefaults(level = AccessLevel.PRIVATE)
public class DefaultEmployeeRepository implements EmployeeRepository, EmployeeTranslatorRepository {
@DubboReference(version = "1.0.0", check = false, registry = "mdm-registry")
IEmployeeQuerySv employeeQuerySv;
@DubboReference(version = "1.0.0", check = false, registry = "account-employee-registry")
IAccountStaffQueryRPCSV accountStaffQueryRpcSv;
final EmployeeConverter converter;
//读取yml配置信息
final EmployeeCacheConfiguration employeeCacheConfiguration;
final EmployeeCache employeeCache;
//被spring管理的bean 在程序启动的时候会调用bean的构造方法
public DefaultEmployeeRepository(EmployeeConverter converter, EmployeeCacheConfiguration employeeCacheConfiguration) {
this.converter = converter;
this.employeeCacheConfiguration = employeeCacheConfiguration;
this.employeeCache = EmployeeCache.builder().time(employeeCacheConfiguration.getTime()).timeUnit(employeeCacheConfiguration.getTimeUnit()).build();
}
}
8.把一个map中的所有value作为list返回
我之前是把map循环了一遍,一个一个放到List中,然后再返回
然后发现有个简单的写法 ArrayList<>(map.values());
Map<EmployeeId, com.ai.ep.domain.employee.Employee> all = new HashMap<>();
return new ArrayList<>(all.values());
9.@EqualsAndHashCode(callSuper = false,of = {"id"})
不用手动重写equals和hashcode方法了
of中指定对比的属性是谁