目录结构:

java之mybatis之使用mybatis实现crud操作

 

1.封装 mybatis 的工具类:

MybatisUtil.java

public class MybatisUtil {
    private static SqlSessionFactory getSqlSessionFactory() throws IOException{
        Reader reader = Resources.getResourceAsReader("mybatis.cfg.xml");
        return  new SqlSessionFactoryBuilder().build(reader);
    }
    public static SqlSession getSqlSession() throws IOException{
        //填写参数 true表示事务自动提交
        return getSqlSessionFactory().openSession(true);
    }
}

2.vo类

User.java

 1 public class User implements Serializable{
 2     private int id;
 3     private String name;
 4     private int age;
 5     public int getId() {
 6         return id;
 7     }
 8     public void setId(int id) {
 9         this.id = id;
10     }
11     public String getName() {
12         return name;
13     }
14     public void setName(String name) {
15         this.name = name;
16     }
17     public int getAge() {
18         return age;
19     }
20     public void setAge(int age) {
21         this.age = age;
22     }
23     @Override
24     public String toString() {
25         return "User [>;
26     }
27 }
View Code

相关文章:

  • 2022-03-10
  • 2021-08-14
  • 2021-07-28
  • 2022-12-23
  • 2021-11-14
  • 2021-07-07
  • 2021-08-10
猜你喜欢
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2022-01-28
  • 2021-05-26
相关资源
相似解决方案