stay ORM In development , For different types , Generally, you need to write different DAO Class to handle data transfer with the database .

    Generally include : add to (add)、 modify (update)、 According to the conditions to query the number of (getCount)、 According to the criteria to query the list (getPage)、 Get a piece of data (get)、 Delete (delete);

    Of course, it also includes some additional interfaces that need to be provided according to specific business scenarios .

    such as : Student (User)、 classroom (Cla***oom)、 Teachers' (Teacher), establish Dao, There's a corresponding one IUserDao、ICla***oomDao、ITeacherDao

    every last Dao The interface needs to have “ Additions and deletions ” operation , You can use generics to handle , This reduces the amount of code ,

    Define a IBaseDao The interface of , as follows :

public interface IBaseDao<T> {
    int add(T t);
    int update (T t);
    int getCount(@Param("searchName")String search);
    List<T> getPage(@Param("searchName")String search,@Param("start")int start,@Param("num")int num);
    T getById(@Param("id")int id);
    List<T> getAll();
    int delete(@Param("id")int id);

To write IUserDao、ICla***oomDao、ITeacherDao Integrate IBaseDao;

notes :Mybatis xml In file  

 <mapper namespace="" > namespace The value of must be globally unique , So you need to create interfaces 

public interface IUserDao extends IBaseDao<User>()

public interface ITeacherDao extends IBaseDao<Teacher>()

public interface ICla***oomDao extends IBaseDao<Cla***oom>()