1 Star 1 Fork 0

这是一个腊鸡/my_mybatis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MySqlSessionImpl.java 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
这是一个腊鸡 提交于 2020-09-26 12:22 . '最基本的mybatis'
package com.mj.mybatis;
import com.mj.dao.IUserMapper;
import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
/**
* @author 马洁
* @date 2020/9/18 - 11:18
*/
public class MySqlSessionImpl implements MySqlSession {
private Connection connection;
private Map<Class<?>, Object> mapper;
public MySqlSessionImpl(Connection connection, Map<String, SqlBean> mapper) {
this.connection = connection;
}
@Override
public IUserMapper getMapper(Class<IUserMapper> iUserMapperClass) {
Object object = mapper.get(iUserMapperClass);
if (object == null) {
object = createProxyClassOfObjectByInterface(iUserMapperClass);
mapper.put(iUserMapperClass, object);
}
return (IUserMapper) object;
}
private Object createProxyClassOfObjectByInterface(Class<IUserMapper> iUserMapperClass) {
return Proxy.newProxyInstance(iUserMapperClass.getClassLoader(), new Class[]{iUserMapperClass},
new MyBatisInvocationHandlerImpl(connection));
}
@Override
public void close() {
try {
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
public static void main(String[] args) {
Connection connection = null;
// MySqlSessionImpl mySqlSession = new MySqlSessionImpl(connection);
// IUserMapper object = (IUserMapper) mySqlSession.createProxyClassOfObjectByInterface(IUserMapper.class);
// System.out.println(object.findAll());
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/TobuMJ/my_mybatis.git
git@gitee.com:TobuMJ/my_mybatis.git
TobuMJ
my_mybatis
my_mybatis
master

搜索帮助