小案例——用户登录、用户注册

用户登录

  

  

用户注册

  

  

  我的Maven项目:https://wwb.lanzoub.com/ien8P0da6ymb

 

 

代码优化

    

 

      工具类:

public class SqlSessionFactoryUtils {

    private static SqlSessionFactory sqlSessionFactory;

    static {

        // 静态代码块 会随类的执行加载而自动执行,且只执行一次

        try {
            // 1、获取 SqlSessionFactory 对象
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static SqlSessionFactory getSqlSessionFactory(){
        return sqlSessionFactory;
    }
}

 

posted @ 2022-10-06 02:14  风陵南  阅读(167)  评论(0)    收藏  举报