开发

2019版本IDEA 使用mybatis插件Free Mybat

2020-01-08  本文已影响0人  Lazy1
微信截图_20200108161048.png 微信截图_20200108161210.png 微信截图_20200108161516.png 微信截图_20200108161657.png 微信截图_20200108161854.png
  private static SqlSessionFactory sqlSessionFactory;
     private static Reader reader;
 
     static {
         try {
             reader = Resources.getResourceAsReader("Configure.xml");
             sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
     public static SqlSessionFactory getSession() {
         return sqlSessionFactory;
     }
 
 
     public static void main(String[] args) {
         SqlSession session = sqlSessionFactory.openSession();
         try {
             UserDao mapper = session.getMapper(UserDao.class);
             User user =mapper.selectByPrimaryKey(1L);
             if(user!=null){
                 String userInfo =user.toString();
                 System.out.println(userInfo);
             }
         } finally {
             session.close();
         }
     }
上一篇 下一篇

猜你喜欢

热点阅读