首先要先了解反射的常用方法:
https://www.cnblogs.com/seeyoumiter/articles/13418776.html
1.写一个SqlSessionFactory工具类
2.写一个SqlSession工具类
3.写一个将ResultSet转为Class对象的工具类
SqlSessionFactory
package com.sunshine.util;
import com.sunshine.session.Session;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class SessionFactory {
DataSource dataSource;
public SessionFactory(){
//创建连接池
DriverManagerDataSource source = new DriverManagerDataSource();
source.setDriverClassName("com.mysql.jdbc.Driver");
source.setUsername("root");
source.setPassword("root");
source.setUrl(&#