1.概念 ①正向工程:Java類→資料庫表 MyBatis不支持 ②逆向工程:資料庫表→Java類 總結:通過MyBatis的jar包自動的生成資料庫所對應的Javabean。 步驟: 1.①創建一個專門的工程用於生成Java文件 先導包: 2.②pom.xml配置 3. ③創建generatorC ...
1.概念
①正向工程:Java類→資料庫表 MyBatis不支持
②逆向工程:資料庫表→Java類
總結:通過MyBatis的jar包自動的生成資料庫所對應的Javabean。
步驟:
1.①創建一個專門的工程用於生成Java文件
先導包:
- log4j-1.2.17.jar:日誌包
- mybatis-3.2.8.jar
- mybatis-generator-core-1.3.2.jar
- mysql-connector-java-5.1.37-bin.jar
2.②pom.xml配置
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.0</version>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
3.
③創建generatorConfig.xml,保存到src/main/resources目錄下
說明信息參見:mybatis-generator-core-1.3.2的官方文檔
<!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="atguiguTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自動生成的註釋 true:是;false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--資料庫連接的信息:驅動類、連接地址、用戶名、密碼 -->
<jdbcConnection
driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mybatis0407"
userId="root"
password="root">
</jdbcConnection>
<!-- 預設false,把JDBC DECIMAL 和 NUMERIC 類型解析為 Integer,為 true時把JDBC DECIMAL
和 NUMERIC 類型解析為java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject:生成Entity類的路徑 -->
<javaModelGenerator targetProject=".\src\main\java" targetPackage="com.atguigu.mybatis.entities">
<!-- enableSubPackages:是否讓schema作為包的尾碼 -->
<property name="enableSubPackages" value="false" />
<!-- 從資料庫返回的值被清理前後的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject:XxxMapper.xml映射文件生成的路徑 -->
<sqlMapGenerator targetProject=".\src\main\java" targetPackage="com.atguigu.mybatis.mappers">
<!-- enableSubPackages:是否讓schema作為包的尾碼 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage:Mapper介面生成的位置 -->
<javaClientGenerator type="XMLMAPPER" targetProject=".\src\main\java" targetPackage="com.atguigu.mybatis.mappers">
<!-- enableSubPackages:是否讓schema作為包的尾碼 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 資料庫表名字和我們的entity類對應的映射指定 -->
<table tableName="tbl_book" domainObjectName="Book" />
</context>
</generatorConfiguration>
4.
④執行Maven命令:mybatis-generator:generate
⑤簡單版context標簽設置:targetRuntime="MyBatis3Simple" defaultModelType="flat"
案例:
1.
2.配置generatorConfig.xml
<!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="atguiguTables" targetRuntime="MyBatis3"> <commentGenerator> <!-- 是否去除自動生成的註釋 true:是;false:否 --> <property name="suppressAllComments" value="FALSE" /> </commentGenerator> <!--資料庫連接的信息:驅動類、連接地址、用戶名、密碼 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="123456"> </jdbcConnection> <!-- 預設false,把JDBC DECIMAL 和 NUMERIC 類型解析為 Integer,為 true時把JDBC DECIMAL 和 NUMERIC 類型解析為java.math.BigDecimal --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- targetProject:生成Entity類的路徑 --> <javaModelGenerator targetProject=".\src" targetPackage="com.atguigu.mybatis.entities"> <!-- enableSubPackages:是否讓schema作為包的尾碼 --> <property name="enableSubPackages" value="false" /> <!-- 從資料庫返回的值被清理前後的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- targetProject:XxxMapper.xml映射文件生成的路徑 --> <sqlMapGenerator targetProject=".\src" targetPackage="com.atguigu.mybatis.mappers"> <!-- enableSubPackages:是否讓schema作為包的尾碼 --> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- targetPackage:Mapper介面生成的位置 --> <javaClientGenerator type="XMLMAPPER" targetProject=".\src" targetPackage="com.atguigu.mybatis.mappers"> <!-- enableSubPackages:是否讓schema作為包的尾碼 --> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 資料庫表名字和我們的entity類對應的映射指定 --> <table tableName="tbl_cust" domainObjectName="Customer" /> </context> </generatorConfiguration>
3.一個測試逆向工程的test類:
package com.gui.bean.test; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.mybatis.generator.api.MyBatisGenerator; import org.mybatis.generator.config.Configuration; import org.mybatis.generator.config.xml.ConfigurationParser; import org.mybatis.generator.exception.XMLParserException; import org.mybatis.generator.internal.DefaultShellCallback; /** * 創建測試生成的bean程式 * * @author Administrator * */ public class CreateBean { @SuppressWarnings("resource") public static void main(String[] args) throws Exception { List<String> warnings = new ArrayList<String>(); boolean overwrite = true; InputStream resourceAsStream = CreateBean .class .getClassLoader() .getResourceAsStream("generatorConfig.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(resourceAsStream); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(null); }
4.測試結果:
自動生成:
代碼如下:
package com.atguigu.mybatis.entities; public class Customer { /** * This field was generated by MyBatis Generator. * This field corresponds to the database column tbl_cust.cust_id * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ private Integer custId; /** * This field was generated by MyBatis Generator. * This field corresponds to the database column tbl_cust.cust_name * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ private String custName; /** * This field was generated by MyBatis Generator. * This field corresponds to the database column tbl_cust.cust_age * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ private Integer custAge; /** * This method was generated by MyBatis Generator. * This method returns the value of the database column tbl_cust.cust_id * * @return the value of tbl_cust.cust_id * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public Integer getCustId() { return custId; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column tbl_cust.cust_id * * @param custId the value for tbl_cust.cust_id * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public void setCustId(Integer custId) { this.custId = custId; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column tbl_cust.cust_name * * @return the value of tbl_cust.cust_name * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public String getCustName() { return custName; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column tbl_cust.cust_name * * @param custName the value for tbl_cust.cust_name * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public void setCustName(String custName) { this.custName = custName == null ? null : custName.trim(); } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column tbl_cust.cust_age * * @return the value of tbl_cust.cust_age * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public Integer getCustAge() { return custAge; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column tbl_cust.cust_age * * @param custAge the value for tbl_cust.cust_age * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public void setCustAge(Integer custAge) { this.custAge = custAge; } }
package com.atguigu.mybatis.entities; import java.util.ArrayList; import java.util.List; public class CustomerExample { /** * This field was generated by MyBatis Generator. * This field corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ protected String orderByClause; /** * This field was generated by MyBatis Generator. * This field corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ protected boolean distinct; /** * This field was generated by MyBatis Generator. * This field corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ protected List<Criteria> oredCriteria; /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public CustomerExample() { oredCriteria = new ArrayList<Criteria>(); } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public void setOrderByClause(String orderByClause) { this.orderByClause = orderByClause; } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public String getOrderByClause() { return orderByClause; } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public void setDistinct(boolean distinct) { this.distinct = distinct; } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public boolean isDistinct() { return distinct; } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public List<Criteria> getOredCriteria() { return oredCriteria; } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public void or(Criteria criteria) { oredCriteria.add(criteria); } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public Criteria or() { Criteria criteria = createCriteriaInternal(); oredCriteria.add(criteria); return criteria; } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public Criteria createCriteria() { Criteria criteria = createCriteriaInternal(); if (oredCriteria.size() == 0) { oredCriteria.add(criteria); } return criteria; } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ protected Criteria createCriteriaInternal() { Criteria criteria = new Criteria(); return criteria; } /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public void clear() { oredCriteria.clear(); orderByClause = null; distinct = false; } /** * This class was generated by MyBatis Generator. * This class corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ protected abstract static class GeneratedCriteria { protected List<Criterion> criteria; protected GeneratedCriteria() { super(); criteria = new ArrayList<Criterion>(); } public boolean isValid() { return criteria.size() > 0; } public List<Criterion> getAllCriteria() { return criteria; } public List<Criterion> getCriteria() { return criteria; } protected void addCriterion(String condition) { if (condition == null) { throw new RuntimeException("Value for condition cannot be null"); } criteria.add(new Criterion(condition)); } protected void addCriterion(String condition, Object value, String property) { if (value == null) { throw new RuntimeException("Value for " + property + " cannot be null"); } criteria.add(new Criterion(condition, value)); } protected void addCriterion(String condition, Object value1, Object value2, String property) { if (value1 == null || value2 == null) { throw new RuntimeException("Between values for " + property + " cannot be null"); } criteria.add(new Criterion(condition, value1, value2)); } public Criteria andCustIdIsNull() { addCriterion("cust_id is null"); return (Criteria) this; } public Criteria andCustIdIsNotNull() { addCriterion("cust_id is not null"); return (Criteria) this; } public Criteria andCustIdEqualTo(Integer value) { addCriterion("cust_id =", value, "custId"); return (Criteria) this; } public Criteria andCustIdNotEqualTo(Integer value) { addCriterion("cust_id <>", value, "custId"); return (Criteria) this; } public Criteria andCustIdGreaterThan(Integer value) { addCriterion("cust_id >", value, "custId"); return (Criteria) this; } public Criteria andCustIdGreaterThanOrEqualTo(Integer value) { addCriterion("cust_id >=", value, "custId"); return (Criteria) this; } public Criteria andCustIdLessThan(Integer value) { addCriterion("cust_id <", value, "custId"); return (Criteria) this; } public Criteria andCustIdLessThanOrEqualTo(Integer value) { addCriterion("cust_id <=", value, "custId"); return (Criteria) this; } public Criteria andCustIdIn(List<Integer> values) { addCriterion("cust_id in", values, "custId"); return (Criteria) this; } public Criteria andCustIdNotIn(List<Integer> values) { addCriterion("cust_id not in", values, "custId"); return (Criteria) this; } public Criteria andCustIdBetween(Integer value1, Integer value2) { addCriterion("cust_id between", value1, value2, "custId"); return (Criteria) this; } public Criteria andCustIdNotBetween(Integer value1, Integer value2) { addCriterion("cust_id not between", value1, value2, "custId"); return (Criteria) this; } public Criteria andCustNameIsNull() { addCriterion("cust_name is null"); return (Criteria) this; } public Criteria andCustNameIsNotNull() { addCriterion("cust_name is not null"); return (Criteria) this; } public Criteria andCustNameEqualTo(String value) { addCriterion("cust_name =", value, "custName"); return (Criteria) this; } public Criteria andCustNameNotEqualTo(String value) { addCriterion("cust_name <>", value, "custName"); return (Criteria) this; } public Criteria andCustNameGreaterThan(String value) { addCriterion("cust_name >", value, "custName"); return (Criteria) this; } public Criteria andCustNameGreaterThanOrEqualTo(String value) { addCriterion("cust_name >=", value, "custName"); return (Criteria) this; } public Criteria andCustNameLessThan(String value) { addCriterion("cust_name <", value, "custName"); return (Criteria) this; } public Criteria andCustNameLessThanOrEqualTo(String value) { addCriterion("cust_name <=", value, "custName"); return (Criteria) this; } public Criteria andCustNameLike(String value) { addCriterion("cust_name like", value, "custName"); return (Criteria) this; } public Criteria andCustNameNotLike(String value) { addCriterion("cust_name not like", value, "custName"); return (Criteria) this; } public Criteria andCustNameIn(List<String> values) { addCriterion("cust_name in", values, "custName"); return (Criteria) this; } public Criteria andCustNameNotIn(List<String> values) { addCriterion("cust_name not in", values, "custName"); return (Criteria) this; } public Criteria andCustNameBetween(String value1, String value2) { addCriterion("cust_name between", value1, value2, "custName"); return (Criteria) this; } public Criteria andCustNameNotBetween(String value1, String value2) { addCriterion("cust_name not between", value1, value2, "custName"); return (Criteria) this; } public Criteria andCustAgeIsNull() { addCriterion("cust_age is null"); return (Criteria) this; } public Criteria andCustAgeIsNotNull() { addCriterion("cust_age is not null"); return (Criteria) this; } public Criteria andCustAgeEqualTo(Integer value) { addCriterion("cust_age =", value, "custAge"); return (Criteria) this; } public Criteria andCustAgeNotEqualTo(Integer value) { addCriterion("cust_age <>", value, "custAge"); return (Criteria) this; } public Criteria andCustAgeGreaterThan(Integer value) { addCriterion("cust_age >", value, "custAge"); return (Criteria) this; } public Criteria andCustAgeGreaterThanOrEqualTo(Integer value) { addCriterion("cust_age >=", value, "custAge"); return (Criteria) this; } public Criteria andCustAgeLessThan(Integer value) { addCriterion("cust_age <", value, "custAge"); return (Criteria) this; } public Criteria andCustAgeLessThanOrEqualTo(Integer value) { addCriterion("cust_age <=", value, "custAge"); return (Criteria) this; } public Criteria andCustAgeIn(List<Integer> values) { addCriterion("cust_age in", values, "custAge"); return (Criteria) this; } public Criteria andCustAgeNotIn(List<Integer> values) { addCriterion("cust_age not in", values, "custAge"); return (Criteria) this; } public Criteria andCustAgeBetween(Integer value1, Integer value2) { addCriterion("cust_age between", value1, value2, "custAge"); return (Criteria) this; } public Criteria andCustAgeNotBetween(Integer value1, Integer value2) { addCriterion("cust_age not between", value1, value2, "custAge"); return (Criteria) this; } } /** * This class was generated by MyBatis Generator. * This class corresponds to the database table tbl_cust * * @mbggenerated do_not_delete_during_merge Sat May 13 18:30:28 CST 2017 */ public static class Criteria extends GeneratedCriteria { protected Criteria() { super(); } } /** * This class was generated by MyBatis Generator. * This class corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ public static class Criterion { private String condition; private Object value; private Object secondValue; private boolean noValue; private boolean singleValue; private boolean betweenValue; private boolean listValue; private String typeHandler; public String getCondition() { return condition; } public Object getValue() { return value; } public Object getSecondValue() { return secondValue; } public boolean isNoValue() { return noValue; } public boolean isSingleValue() { return singleValue; } public boolean isBetweenValue() { return betweenValue; } public boolean isListValue() { return listValue; } public String getTypeHandler() { return typeHandler; } protected Criterion(String condition) { super(); this.condition = condition; this.typeHandler = null; this.noValue = true; } protected Criterion(String condition, Object value, String typeHandler) { super(); this.condition = condition; this.value = value; this.typeHandler = typeHandler; if (value instanceof List<?>) { this.listValue = true; } else { this.singleValue = true; } } protected Criterion(String condition, Object value) { this(condition, value, null); } protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { super(); this.condition = condition; this.value = value; this.secondValue = secondValue; this.typeHandler = typeHandler; this.betweenValue = true; } protected Criterion(String condition, Object value, Object secondValue) { this(condition, value, secondValue, null); } } }
CustomerMapper.java
package com.atguigu.mybatis.mappers; import com.atguigu.mybatis.entities.Customer; import com.atguigu.mybatis.entities.CustomerExample; import java.util.List; import org.apache.ibatis.annotations.Param; public interface CustomerMapper { /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int countByExample(CustomerExample example); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int deleteByExample(CustomerExample example); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int deleteByPrimaryKey(Integer custId); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int insert(Customer record); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int insertSelective(Customer record); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ List<Customer> selectByExample(CustomerExample example); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ Customer selectByPrimaryKey(Integer custId); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int updateByExampleSelective(@Param("record") Customer record, @Param("example") CustomerExample example); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int updateByExample(@Param("record") Customer record, @Param("example") CustomerExample example); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int updateByPrimaryKeySelective(Customer record); /** * This method was generated by MyBatis Generator. * This method corresponds to the database table tbl_cust * * @mbggenerated Sat May 13 18:30:28 CST 2017 */ int updateByPrimaryKey(Customer record); }
CustomerMapper.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="com.atguigu.mybatis.mappers.CustomerMapper"> <resultMap id="BaseResultMap" type="com.atguigu.mybatis.entities.Customer"> <!-- WARNING - @mbggenerated This element is automatically generated by MyBatis Generator, do not modify. This element was generated on Sat May 13 18:30:28 CST 2017. --> <id column="cust_id" property="custId" jdbcType="INTEGER" /> <result column="cust_name" property="custName" jdbcType="CHAR" /> <result column="cust_age" property="custAge" jdbcType="INTEGER" /> </resultMap> <sql id="Example_Where_Clause"> <!-- WARNING - @mbggenerated This element is automatically generated by MyBatis Generator, do not modify. This element was generated on Sat May 13 18:30:28 CST 2017. --> <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"> <!-- WARNING - @mbggenerated This element is automatically generated by MyBatis Generator, do not modify. This element was generated on Sat May 13 18:30:28 CST 2017. --> <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"> <!-- WARNING - @mbggenerated This element is automatically generated by MyBatis Generator, do not modify. This element was generated on Sat May 13 18:30:28 CST 2017. --> cust_id, cust_name, cust_age </sql> <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.atguigu.mybatis.entities.CustomerExample"> <!-- WARNING - @mbggenerated This element is automatically generated by MyBatis Generator, do not modify. This element was generated on Sat May 13 18:30:28 CST 2017. --> select <if test="distinct">