发电机如何在mybatis中使用

  介绍

这期内容当中小编将会给大家带来有关发电机如何在mybatis中使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

最近的一个项目,由于数据库表巨多,导致需要创建N多个java实体,刀,映射器。xml映射文件,如果均使用纯手工编写,无疑需要耗费大量时间和精力。于是上网学习了mybatis发生器的使用。

现在项目写完了,闲暇之余把干货奉上,供大家直接使用。

当你的java项目数据库有N张表需要使用mybatis进行数据库操作时,建议使用mybatis发电机自动生成工具。可以自动帮助你生成java实体类,刀,映射器。xml等。

首先给大家分享我自己封装好的mybatis发电机代码自动生成项目,里面集成了中文注释,mysql的极限分页功能。

此外需要注意<强>需要重新引入一下jar文件夹中的mybatis-generator-plugin-1.0.0。jar ,如图:

发电机如何在mybatis中使用“> </p> <p> <强>最终目录结构如下</强>:</p> <p> <img src= @Test   公共空间testQueryStudentExample () {   SqlSession SqlSession=sqlSessionFactory.openSession(假);   StudentMapper StudentMapper=sqlSession.getMapper (StudentMapper.class);   尝试{//分页查询性别为男,并且名称中包含z的记录,第一页,每页3条记录,按性别排序   StudentExample StudentExample=new StudentExample ();   studentExample.or () .andGenderEqualTo (1) .andNameLike (“% z %“);   studentExample.setOffset (0);   studentExample.setLimit (3);   studentExample.setOrderByClause(“性别DESC");      Listlist1=studentMapper.selectByExample (studentExample);   List用于=studentMapper.selectByExampleWithBLOBs (studentExample);   System.out.println (list1.get (0) .getDisc ());   System.out.println (list2.get (0) .getDisc ());   }捕捉(异常e) {   e.printStackTrace ();   sqlSession.rollback ();   最后}{   sqlSession.close ();   }   }

发电机如何在mybatis中使用