代码拉取完成,页面将自动刷新
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());
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。