逆向工程能夠快速將數據庫的表生成JavaBean,同時生成對單標操做的Mapper.java與Mapper.xml,極大地提升了開發速度。java
1.jar包mysql
2.配置文件spring
須要修改數據庫鏈接信息,mapper生成目錄與pojo生成位置,也要修改要導出的表。sql
工程目錄下配置generatorConfig.xml數據庫
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <context id="testTables" targetRuntime="MyBatis3"> <commentGenerator> <!-- 是否去除自動生成的註釋 true:是 : false:否 --> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--數據庫鏈接的信息:驅動類、鏈接地址、用戶名、密碼 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/exam" userId="root" password="123456"> </jdbcConnection> <!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver" connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg" userId="yycg" password="yycg"> </jdbcConnection> --> <!-- 默認false,把JDBC DECIMAL 和 NUMERIC 類型解析爲 Integer,爲 true時把JDBC DECIMAL 和 NUMERIC 類型解析爲java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- targetProject:生成PO類的位置 --> <javaModelGenerator targetPackage="cn.xm.pojo" targetProject=".\src"> <!-- enableSubPackages:是否讓schema做爲包的後綴 --> <property name="enableSubPackages" value="false" /> <!-- 從數據庫返回的值被清理先後的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- targetProject:mapper映射文件生成的位置 --> <sqlMapGenerator targetPackage="cn.xm.mapper" targetProject=".\src"> <!-- enableSubPackages:是否讓schema做爲包的後綴 --> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- targetPackage:mapper接口生成的位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="cn.xm.mapper" targetProject=".\src"> <!-- enableSubPackages:是否讓schema做爲包的後綴 --> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 指定數據庫表 --> <table tableName="blacklist"></table> <table tableName="breakrules"></table> <table tableName="checkrecord"></table> <table tableName="department"></table> <table tableName="dictionary"></table> <table tableName="employee_in"></table> <table tableName="employee_out"></table> <table tableName="employeeexam"></table> <table tableName="exam"></table> <table tableName="exampaper"></table> <table tableName="historypaperoption"></table> <table tableName="historypaperquestion"></table> <table tableName="newsrecord"></table> <table tableName="onlineexamanswerinfor"></table> <table tableName="onlineexaminfor"></table> <table tableName="options"></table> <table tableName="permission"></table> <table tableName="pictureindex"></table> <table tableName="project"></table> <table tableName="questionbank"></table> <table tableName="questions"></table> <table tableName="role"></table> <table tableName="rolepermission"></table> <table tableName="traincontent"></table> <table tableName="unit"></table> <table tableName="unitproject"></table> <table tableName="userrole"></table> </context> </generatorConfiguration>
3. Java程序apache
1 package mybatisInverse; 2 import java.io.File; 3 import java.util.ArrayList; 4 import java.util.List; 5 import org.mybatis.generator.api.MyBatisGenerator; 6 import org.mybatis.generator.config.Configuration; 7 import org.mybatis.generator.config.xml.ConfigurationParser; 8 import org.mybatis.generator.internal.DefaultShellCallback; 9 10 public class GeneratorSqlmap 11 { 12 public void generator() 13 throws Exception 14 { 15 List<String> warnings = new ArrayList(); 16 boolean overwrite = true; 17 18 File configFile = new File("generatorConfig.xml"); 19 ConfigurationParser cp = new ConfigurationParser(warnings); 20 Configuration config = cp.parseConfiguration(configFile); 21 DefaultShellCallback callback = new DefaultShellCallback(overwrite); 22 MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, 23 callback, warnings); 24 myBatisGenerator.generate(null); 25 } 26 27 public static void main(String[] args) 28 throws Exception 29 { 30 try 31 { 32 GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap(); 33 generatorSqlmap.generator(); 34 } 35 catch (Exception e) 36 { 37 e.printStackTrace(); 38 } 39 } 40 }
運行結果:api
4.使用生成的代碼:tomcat
對單表操做較方便,能夠自定義條件查詢。session
sqlMapConfig.xmlmybatis
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 加載屬性文件 --> <properties resource="db.properties"> <!--properties中還能夠配置一些屬性名和屬性值 --> <!-- <property name="jdbc.driver" value=""/> --> </properties> <!-- 全局配置參數,須要時再設置 --> <!-- <settings> </settings> --> <!-- 別名定義 --> <typeAliases> <!-- 針對單個別名定義 type:類型的路徑 alias:別名 --> <!-- <typeAlias type="cn.itcast.mybatis.po.User" alias="user"/> --> <!-- 批量別名定義 指定包名,mybatis自動掃描包中的po類,自動定義別名,別名就是類名(首字母大寫或小寫均可以) --> <package name="cn.xm.pojo"/> </typeAliases> <!-- 和spring整合後 environments配置將廢除--> <environments default="development"> <environment id="development"> <!-- 使用jdbc事務管理,事務控制由mybatis--> <transactionManager type="JDBC" /> <!-- 數據庫鏈接池,由mybatis管理--> <dataSource type="POOLED"> <property name="driver" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </dataSource> </environment> </environments> <!-- 加載 映射文件 --> <mappers> <!--經過resource方法一次加載一個映射文件 --> <!-- <mapper resource="mapper/UserMapper.xml"/> --> <!-- 經過mapper接口加載單個 映射文件 遵循一些規範:須要將mapper接口類名和mapper.xml映射文件名稱保持一致,且在一個目錄 中 上邊規範的前提是:使用的是mapper代理方法 --> <!-- <mapper class="cn.itcast.mybatis.mapper.UserMapper"/> --> <!-- 批量加載mapper 指定mapper接口的包名,mybatis自動掃描包下邊全部mapper接口進行加載 遵循一些規範:須要將mapper接口類名和mapper.xml映射文件名稱保持一致,且在一個目錄 中 上邊規範的前提是:使用的是mapper代理方法 --> <package name="cn.xm.mapper"/> </mappers> </configuration>
java代碼:
package cn.xm.test; import java.io.InputStream; import java.net.URL; import java.util.Date; import java.util.List; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmxMBean; import org.junit.Before; import org.junit.Test; import cn.xm.mapper.EmployeeInMapper; import cn.xm.pojo.EmployeeIn; import cn.xm.pojo.EmployeeInExample; public class MybatisTest { private SqlSessionFactory sqlSessionFactory; @Before public void setUp() throws Exception { // 將全局配置文件做爲一個流 String resource = "sqlMapConfig.xml"; URL realPath2 = Resources.getResourceURL("sqlMapConfig.xml"); InputStream inputStream = Resources.getResourceAsStream(resource); // 創建一個SqlSession工廠 sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); } // 測試增長 @Test public void testAdd() throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); EmployeeInMapper eim = sqlSession.getMapper(EmployeeInMapper.class); EmployeeIn sl = new EmployeeIn(); sl.setIdcode("33"); sl.setEmployeeid("3"); sl.setEmployeenumber("3"); sl.setPassword("33333"); ; sl.setName("王五"); eim.insert(sl); sqlSession.commit(); sqlSession.close(); } // 測試刪除 @Test public void testDeleteById() throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); EmployeeInMapper eim = sqlSession.getMapper(EmployeeInMapper.class); eim.deleteByPrimaryKey("3"); sqlSession.commit(); sqlSession.close(); } // 測試修改 @Test public void fun2() throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); EmployeeInMapper eim = sqlSession.getMapper(EmployeeInMapper.class); EmployeeIn selectByPrimaryKey = eim.selectByPrimaryKey("3"); selectByPrimaryKey.setName("這是修改後的值"); eim.updateByPrimaryKey(selectByPrimaryKey); sqlSession.commit(); sqlSession.close(); } // 測試經過id查詢單個 @Test public void fun3() throws Exception { SqlSession sqlSession = sqlSessionFactory.openSession(); EmployeeInMapper eim = sqlSession.getMapper(EmployeeInMapper.class); EmployeeIn selectByPrimaryKey = eim.selectByPrimaryKey("3"); System.out.println(selectByPrimaryKey); } // 自定義條件查詢 查詢名字爲張三的 @Test public void testSelectByExample() { SqlSession sqlSession = sqlSessionFactory.openSession(); EmployeeInMapper eim = sqlSession.getMapper(EmployeeInMapper.class); EmployeeInExample employeeInExample = new EmployeeInExample(); // 經過criteria構造查詢條件 EmployeeInExample.Criteria criteria = employeeInExample.createCriteria(); criteria.andNameEqualTo("張三"); // 可能返回多條記錄 List<EmployeeIn> list = eim.selectByExample(employeeInExample); System.out.println(list); } // 自定義條件查詢 查詢名字爲張三的且password爲44444的 @Test public void testSelectByExample1() { SqlSession sqlSession = sqlSessionFactory.openSession(); EmployeeInMapper eim = sqlSession.getMapper(EmployeeInMapper.class); EmployeeInExample employeeInExample = new EmployeeInExample(); // 經過criteria構造查詢條件 EmployeeInExample.Criteria criteria = employeeInExample.createCriteria(); criteria.andNameEqualTo("張三"); criteria.andPasswordEqualTo("44444"); // 可能返回多條記錄 List<EmployeeIn> list = eim.selectByExample(employeeInExample); System.out.println(list); } // 自定義條件查詢 查詢全部,只是不封裝條件 @Test public void testSelectByExample3() { SqlSession sqlSession = sqlSessionFactory.openSession(); EmployeeInMapper eim = sqlSession.getMapper(EmployeeInMapper.class); EmployeeInExample employeeInExample = new EmployeeInExample(); // 經過criteria構造查詢條件 EmployeeInExample.Criteria criteria = employeeInExample.createCriteria(); // 可能返回多條記錄 List<EmployeeIn> list = eim.selectByExample(employeeInExample); System.out.println(list); } }
補充:今天我同窗問我如何用Criteria去執行相似於or的語句,例如:select * from user where usercode="lll" or password="lll"
通過網上查閱資料發現是從新再構造一個criteria,並手動注入到example中:
@Test public void test1(){ UserExample userExample = new UserExample(); UserExample.Criteria criteria_1 = userExample.createCriteria(); criteria_1.andUsercodeEqualTo("111"); UserExample.Criteria criteria_2 = userExample.createCriteria(); criteria_2.andPasswordEqualTo("111"); userExample.or(criteria_2); List<User> users = userMapper.selectByExample(userExample); for(User u:users){ System.out.println("--------------------SSSSSSSSSSSSSSSSSSSSSSSSS------------"+u); } }
查看日誌:
16:37:15,550 DEBUG selectByExample:132 - ==> Preparing: select userID, userCode, userName, password, userSort, remark2 from user WHERE ( userCode = ? ) or( password = ? )
16:37:15,622 DEBUG selectByExample:132 - ==> Parameters: 111(String), 111(String)
另外逆向工程導出的mapper還能夠設置排序和distinct
public void test1(){ UserExample userExample = new UserExample(); /*封裝查詢條件*/ UserExample.Criteria criteria_1 = userExample.createCriteria(); criteria_1.andUsercodeEqualTo("111"); UserExample.Criteria criteria_2 = userExample.createCriteria(); criteria_2.andPasswordEqualTo("111"); userExample.or(criteria_2); /*封裝排序(姓名降序-密碼升序)*/ userExample.setOrderByClause("username desc,password"); /*是不是distinct*/ userExample.setDistinct(true); List<User> users = userMapper.selectByExample(userExample); for(User u:users){ System.out.println(u); } }
查看日誌
16:43:09,575 DEBUG selectByExample:132 - ==> Preparing: select distinct userID, userCode, userName, password, userSort, remark2 from user WHERE ( userCode = ? ) or( password = ? ) order by username desc,password
16:43:09,670 DEBUG selectByExample:132 - ==> Parameters: 111(String), 111(String)
使用逆向工程修改指定的列;
相似於直接修改。
若是調用:
若是某些列爲空它也會指控。相似於先刪除而後添加。添加後來新的對象。
最後附一個完整的mapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="cn.xm.exam.mapper.trainContent.TraincontentMapper" > <resultMap id="BaseResultMap" type="cn.xm.exam.bean.trainContent.Traincontent" > <id column="documentId" property="documentid" jdbcType="INTEGER" /> <result column="departmentId" property="departmentid" jdbcType="VARCHAR" /> <result column="documentName" property="documentname" jdbcType="VARCHAR" /> <result column="trainType" property="traintype" jdbcType="VARCHAR" /> <result column="departmentName" property="departmentname" jdbcType="VARCHAR" /> <result column="knowledgeType" property="knowledgetype" jdbcType="VARCHAR" /> <result column="originalName" property="originalname" jdbcType="VARCHAR" /> <result column="currentName" property="currentname" jdbcType="VARCHAR" /> <result column="upTime" property="uptime" jdbcType="TIMESTAMP" /> <result column="size" property="size" jdbcType="VARCHAR" /> <result column="employeeName" property="employeename" jdbcType="VARCHAR" /> <result column="level" property="level" jdbcType="VARCHAR" /> <result column="description" property="description" jdbcType="VARCHAR" /> <result column="browseTimes" property="browsetimes" jdbcType="INTEGER" /> </resultMap> <sql id="Example_Where_Clause" > <where > <foreach collection="oredCriteria" item="criteria" separator="or" > <if test="criteria.valid" > <trim prefix="(" suffix=")" prefixOverrides="and" > <foreach collection="criteria.criteria" item="criterion" > <choose > <when test="criterion.noValue" > and ${criterion.condition} </when> <when test="criterion.singleValue" > and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue" > and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue" > and ${criterion.condition} <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <sql id="Update_By_Example_Where_Clause" > <where > <foreach collection="example.oredCriteria" item="criteria" separator="or" > <if test="criteria.valid" > <trim prefix="(" suffix=")" prefixOverrides="and" > <foreach collection="criteria.criteria" item="criterion" > <choose > <when test="criterion.noValue" > and ${criterion.condition} </when> <when test="criterion.singleValue" > and ${criterion.condition} #{criterion.value} </when> <when test="criterion.betweenValue" > and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} </when> <when test="criterion.listValue" > and ${criterion.condition} <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > #{listItem} </foreach> </when> </choose> </foreach> </trim> </if> </foreach> </where> </sql> <sql id="Base_Column_List" > documentId, departmentId, documentName, trainType, departmentName, knowledgeType, originalName, currentName, upTime, size, employeeName, level, description, browseTimes </sql> <select id="selectByExample" resultMap="BaseResultMap" parameterType="cn.xm.exam.bean.trainContent.TraincontentExample" > select <if test="distinct" > distinct </if> <include refid="Base_Column_List" /> from traincontent <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null" > order by ${orderByClause} </if> </select> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> from traincontent where documentId = #{documentid,jdbcType=INTEGER} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > delete from traincontent where documentId = #{documentid,jdbcType=INTEGER} </delete> <delete id="deleteByExample" parameterType="cn.xm.exam.bean.trainContent.TraincontentExample" > delete from traincontent <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> </delete> <insert id="insert" parameterType="cn.xm.exam.bean.trainContent.Traincontent" > insert into traincontent (documentId, departmentId, documentName, trainType, departmentName, knowledgeType, originalName, currentName, upTime, size, employeeName, level, description, browseTimes) values (#{documentid,jdbcType=INTEGER}, #{departmentid,jdbcType=VARCHAR}, #{documentname,jdbcType=VARCHAR}, #{traintype,jdbcType=VARCHAR}, #{departmentname,jdbcType=VARCHAR}, #{knowledgetype,jdbcType=VARCHAR}, #{originalname,jdbcType=VARCHAR}, #{currentname,jdbcType=VARCHAR}, #{uptime,jdbcType=TIMESTAMP}, #{size,jdbcType=VARCHAR}, #{employeename,jdbcType=VARCHAR}, #{level,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{browsetimes,jdbcType=INTEGER}) </insert> <insert id="insertSelective" parameterType="cn.xm.exam.bean.trainContent.Traincontent" > insert into traincontent <trim prefix="(" suffix=")" suffixOverrides="," > <if test="documentid != null" > documentId, </if> <if test="departmentid != null" > departmentId, </if> <if test="documentname != null" > documentName, </if> <if test="traintype != null" > trainType, </if> <if test="departmentname != null" > departmentName, </if> <if test="knowledgetype != null" > knowledgeType, </if> <if test="originalname != null" > originalName, </if> <if test="currentname != null" > currentName, </if> <if test="uptime != null" > upTime, </if> <if test="size != null" > size, </if> <if test="employeename != null" > employeeName, </if> <if test="level != null" > level, </if> <if test="description != null" > description, </if> <if test="browsetimes != null" > browseTimes, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="documentid != null" > #{documentid,jdbcType=INTEGER}, </if> <if test="departmentid != null" > #{departmentid,jdbcType=VARCHAR}, </if> <if test="documentname != null" > #{documentname,jdbcType=VARCHAR}, </if> <if test="traintype != null" > #{traintype,jdbcType=VARCHAR}, </if> <if test="departmentname != null" > #{departmentname,jdbcType=VARCHAR}, </if> <if test="knowledgetype != null" > #{knowledgetype,jdbcType=VARCHAR}, </if> <if test="originalname != null" > #{originalname,jdbcType=VARCHAR}, </if> <if test="currentname != null" > #{currentname,jdbcType=VARCHAR}, </if> <if test="uptime != null" > #{uptime,jdbcType=TIMESTAMP}, </if> <if test="size != null" > #{size,jdbcType=VARCHAR}, </if> <if test="employeename != null" > #{employeename,jdbcType=VARCHAR}, </if> <if test="level != null" > #{level,jdbcType=VARCHAR}, </if> <if test="description != null" > #{description,jdbcType=VARCHAR}, </if> <if test="browsetimes != null" > #{browsetimes,jdbcType=INTEGER}, </if> </trim> </insert> <select id="countByExample" parameterType="cn.xm.exam.bean.trainContent.TraincontentExample" resultType="java.lang.Integer" > select count(*) from traincontent <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> </select> <update id="updateByExampleSelective" parameterType="map" > update traincontent <set > <if test="record.documentid != null" > documentId = #{record.documentid,jdbcType=INTEGER}, </if> <if test="record.departmentid != null" > departmentId = #{record.departmentid,jdbcType=VARCHAR}, </if> <if test="record.documentname != null" > documentName = #{record.documentname,jdbcType=VARCHAR}, </if> <if test="record.traintype != null" > trainType = #{record.traintype,jdbcType=VARCHAR}, </if> <if test="record.departmentname != null" > departmentName = #{record.departmentname,jdbcType=VARCHAR}, </if> <if test="record.knowledgetype != null" > knowledgeType = #{record.knowledgetype,jdbcType=VARCHAR}, </if> <if test="record.originalname != null" > originalName = #{record.originalname,jdbcType=VARCHAR}, </if> <if test="record.currentname != null" > currentName = #{record.currentname,jdbcType=VARCHAR}, </if> <if test="record.uptime != null" > upTime = #{record.uptime,jdbcType=TIMESTAMP}, </if> <if test="record.size != null" > size = #{record.size,jdbcType=VARCHAR}, </if> <if test="record.employeename != null" > employeeName = #{record.employeename,jdbcType=VARCHAR}, </if> <if test="record.level != null" > level = #{record.level,jdbcType=VARCHAR}, </if> <if test="record.description != null" > description = #{record.description,jdbcType=VARCHAR}, </if> <if test="record.browsetimes != null" > browseTimes = #{record.browsetimes,jdbcType=INTEGER}, </if> </set> <if test="_parameter != null" > <include refid="Update_By_Example_Where_Clause" /> </if> </update> <update id="updateByExample" parameterType="map" > update traincontent set documentId = #{record.documentid,jdbcType=INTEGER}, departmentId = #{record.departmentid,jdbcType=VARCHAR}, documentName = #{record.documentname,jdbcType=VARCHAR}, trainType = #{record.traintype,jdbcType=VARCHAR}, departmentName = #{record.departmentname,jdbcType=VARCHAR}, knowledgeType = #{record.knowledgetype,jdbcType=VARCHAR}, originalName = #{record.originalname,jdbcType=VARCHAR}, currentName = #{record.currentname,jdbcType=VARCHAR}, upTime = #{record.uptime,jdbcType=TIMESTAMP}, size = #{record.size,jdbcType=VARCHAR}, employeeName = #{record.employeename,jdbcType=VARCHAR}, level = #{record.level,jdbcType=VARCHAR}, description = #{record.description,jdbcType=VARCHAR}, browseTimes = #{record.browsetimes,jdbcType=INTEGER} <if test="_parameter != null" > <include refid="Update_By_Example_Where_Clause" /> </if> </update> <update id="updateByPrimaryKeySelective" parameterType="cn.xm.exam.bean.trainContent.Traincontent" > update traincontent <set > <if test="departmentid != null" > departmentId = #{departmentid,jdbcType=VARCHAR}, </if> <if test="documentname != null" > documentName = #{documentname,jdbcType=VARCHAR}, </if> <if test="traintype != null" > trainType = #{traintype,jdbcType=VARCHAR}, </if> <if test="departmentname != null" > departmentName = #{departmentname,jdbcType=VARCHAR}, </if> <if test="knowledgetype != null" > knowledgeType = #{knowledgetype,jdbcType=VARCHAR}, </if> <if test="originalname != null" > originalName = #{originalname,jdbcType=VARCHAR}, </if> <if test="currentname != null" > currentName = #{currentname,jdbcType=VARCHAR}, </if> <if test="uptime != null" > upTime = #{uptime,jdbcType=TIMESTAMP}, </if> <if test="size != null" > size = #{size,jdbcType=VARCHAR}, </if> <if test="employeename != null" > employeeName = #{employeename,jdbcType=VARCHAR}, </if> <if test="level != null" > level = #{level,jdbcType=VARCHAR}, </if> <if test="description != null" > description = #{description,jdbcType=VARCHAR}, </if> <if test="browsetimes != null" > browseTimes = #{browsetimes,jdbcType=INTEGER}, </if> </set> where documentId = #{documentid,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="cn.xm.exam.bean.trainContent.Traincontent" > update traincontent set departmentId = #{departmentid,jdbcType=VARCHAR}, documentName = #{documentname,jdbcType=VARCHAR}, trainType = #{traintype,jdbcType=VARCHAR}, departmentName = #{departmentname,jdbcType=VARCHAR}, knowledgeType = #{knowledgetype,jdbcType=VARCHAR}, originalName = #{originalname,jdbcType=VARCHAR}, currentName = #{currentname,jdbcType=VARCHAR}, upTime = #{uptime,jdbcType=TIMESTAMP}, size = #{size,jdbcType=VARCHAR}, employeeName = #{employeename,jdbcType=VARCHAR}, level = #{level,jdbcType=VARCHAR}, description = #{description,jdbcType=VARCHAR}, browseTimes = #{browsetimes,jdbcType=INTEGER} where documentId = #{documentid,jdbcType=INTEGER} </update> </mapper>
附一個測試工程的下載地址: http://qiaoliqiang.cn/fileDown/MybatisInverse.zip