hiherante中对日期和钱的类型转换
Jadira Usertype Core
Classes utilising Joda Time, Joda Money, Libphonenum and JDK Types that add Hibernate support
spring JPA(定义+操作),实体、主键、关系。操作,Repository
public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>{}
public interface PagingAndSortingRepository<T, ID> extends CrudRepository<T, ID>{}
public interface CrudRepository<T, ID> extends Repository<T, ID>{}
根据方法名定义查询+分页查询
- Repository如何从接口变成Bean的。
public <T extends RepositoryConfigurationSource> Collection<RepositoryConfiguration<T>> getRepositoryConfigurations(){
for (BeanDefinition candidate : configSource.getCandidates(loader)) {}
}
JpaRepositoryFactory.getTargetRepository方法创建类!!
- 接⼝口中的方法是如何被解释的.AoP
// Create proxy
ProxyFactory result = new ProxyFactory();
result.setTarget(target);
result.setInterfaces(repositoryInterface, Repository.class, TransactionalProxy.class);
if (DefaultMethodInvokingMethodInterceptor.hasDefaultMethods(repositoryInterface)) {
result.addAdvice(new DefaultMethodInvokingMethodInterceptor());
}
result.addAdvice(new QueryExecutorMethodInterceptor(information, projectionFactory, queryLookupStrategy,
namedQueries, queryPostProcessors));
public class PartTree implements Streamable<OrPart> {
方法解析位于PartTree中!关键字的定义模式为p{Lu}
private static final String KEYWORD_TEMPLATE = "(%s)(?=(\\p{Lu}|...";
private static final String QUERY_PATTERN = "find|read|get|query|stream";
private static final String COUNT_PATTERN = "count";
private static final String EXISTS_PATTERN = "exists";
private static final String DELETE_PATTERN = "delete|remove";
mybatis的简单配置
mapper-location,type-aliases-package.
//mybatis.type-handlers-package=geektime.spring.data.mybatisdemo.handler
/**
* 在 Money 与 Long 之间转换的 TypeHandler,处理 CNY 人民币
*/
public class MoneyTypeHandler extends BaseTypeHandler<Money> {}
Mapper的定义与扫描
- @MapperScan配置扫描位置
- @Mapper定义接口
- 映射的定义–XML或注解
mybatis工具。1. MyBatis Generator,根据数据库表生成相关代码,例如POJO,Mapper接口,SQL Mapper XML。通过resources/generatorConfig.xml
配置。1.简单对象,xxxMapper方法,复杂查询,使用xxxExample对象
2.MyBatis PageHelper RowBounds