MyBatis 使用简单的 XML 或注解用于配置和原始映射,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java 对象)映射成数据库中的记录。每个 MyBatis 应用程序主要都是使用 SqlSessionFactory 实例的,一个 SqlSessionFactory 实例可以通过 SqlSessionFactoryBuilder 获得。SqlSessionFactoryBuilder 可以从一个 xml 配置文件或者一个预定义的配置类的实例获得。

使用框架就是引用别人封装好的 jar 包,按照别人规定好的方式进行配置并调用 jar 包里的各种方法。那 Mybatis 需要进行哪些配置呢?我们来看一个例子:

在JavaEE中使用Mybatis框架 

一、使用XML实现数据的访问

1、创建简单的 POJO 类

在JavaEE中使用Mybatis框架
package com.wenji.entity;

public class Employee {
       private int id;
       private String firstName; 
       private String lastName;   
       private int salary;  

       public Employee() {}
       public Employee(int id,String firstName, String lastName, int salary) {
          this.id = id;
          this.firstName = firstName;
          this.lastName = lastName;
          this.salary = salary;
       }
       //省略getter、setter方法
}
Employee类

相关文章:

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