springboot学习笔记 第三章

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>{}

根据方法名定义查询+分页查询

  1. Repository如何从接口变成Bean的。
	public <T extends RepositoryConfigurationSource> Collection<RepositoryConfiguration<T>> getRepositoryConfigurations(){
        for (BeanDefinition candidate : configSource.getCandidates(loader)) {}
    }

JpaRepositoryFactory.getTargetRepository方法创建类!!

  1. 接⼝口中的方法是如何被解释的.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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值