public <T> T getMapper(Class<T> type, SqlSession sqlSession){ final MapperProxyFactory<T> mapperProxyFactory = (MapperProxyFactory<T>) knownMappers.get(type); if (mapperProxyFactory == null) { thrownew RuntimeException("Type " + type + " is not known to the MapperRegistry."); } try { return mapperProxyFactory.newInstance(sqlSession); } catch (Exception e) { thrownew RuntimeException("Error getting mapper instance. Cause: " + e, e); } }
public <T> voidaddMapper(Class<T> type){ /* Mapper 必须是接口才会注册 */ if (type.isInterface()) { if (hasMapper(type)) { // 如果重复添加了,报错 thrownew RuntimeException("Type " + type + " is already known to the MapperRegistry."); } // 注册映射器代理工厂 knownMappers.put(type, new MapperProxyFactory<>(type)); } }
/** * Retrieve a single row mapped from the statement key * 根据指定的SqlID获取一条记录的封装对象 * * @param <T> the returned object type 封装之后的对象类型 * @param statement sqlID * @return Mapped object 封装之后的对象 */ <T> T selectOne(String statement);
/** * Retrieve a single row mapped from the statement key and parameter. * 根据指定的SqlID获取一条记录的封装对象,只不过这个方法容许我们可以给sql传递一些参数 * 一般在实际使用中,这个参数传递的是pojo,或者Map或者ImmutableMap * * @param <T> the returned object type * @param statement Unique identifier matching the statement to use. * @param parameter A parameter object to pass to the statement. * @return Mapped object */ <T> T selectOne(String statement, Object parameter);
/** * Retrieves a mapper. * 得到映射器,这个巧妙的使用了泛型,使得类型安全 * * @param <T> the mapper type * @param type Mapper interface class * @return a mapper bound to this SqlSession */ <T> T getMapper(Class<T> type);
Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。