逆向工程

来源:http://www.cnblogs.com/likeyou1/archive/2017/05/13/6849916.html
-Advertisement-
Play Games

1.概念 ①正向工程:Java類→資料庫表 MyBatis不支持 ②逆向工程:資料庫表→Java類 總結:通過MyBatis的jar包自動的生成資料庫所對應的Javabean。 步驟: 1.①創建一個專門的工程用於生成Java文件 先導包: 2.②pom.xml配置 3. ③創建generatorC ...


1.概念
①正向工程:Java類→資料庫表 MyBatis不支持
②逆向工程:資料庫表→Java類

總結:通過MyBatis的jar包自動的生成資料庫所對應的Javabean。

步驟:

1.①創建一個專門的工程用於生成Java文件

 先導包: 

  1. log4j-1.2.17.jar:日誌包
  2. mybatis-3.2.8.jar
  3. mybatis-generator-core-1.3.2.jar
  4. 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">
              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 題目描述 對於給定的一個長度為N的正整數數列A[i],現要將其分成連續的若幹段,並且每段和不超過M(可以等於M),問最少能將其分成多少段使得滿足要求。 輸入輸出格式 輸入格式: 輸入文件divide_a.in的第1行包含兩個正整數N,M,表示了數列A[i]的長度與每段和的最大值,第2行包含N個空格隔 ...
  • JavaMail,提供給開發者處理電子郵件相關的編程介面。它是Sun發佈的用來處理email的API。它可以方便地執行一些常用的郵件傳輸。但它並沒有包含在JDK中,要使用JavaMail首先要下載javax.mail.jar下載地址:https://javaee.github.io/javamail ...
  • The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return al... ...
  • 題目描述 如題,給出一個無向圖,求出最小生成樹,如果該圖不連通,則輸出orz 輸入輸出格式 輸入格式: 第一行包含兩個整數N、M,表示該圖共有N個結點和M條無向邊。(N<=5000,M<=200000) 接下來M行每行包含三個整數Xi、Yi、Zi,表示有一條長度為Zi的無向邊連接結點Xi、Yi 輸出 ...
  • HashMap的設計是由數組加鏈表的符合數據結構,在這裡用自己的語言以及結合源碼去總結一下,如果有不對的地方希望評論指正,先拱手謝謝。 HashMap是日常中非常常用的一種數據結構,我們要想深入瞭解學習任何一門技術,都是要先應用,再深入。深入就要瞭解實現的原理,在java語言中,最基本的結構是數組以 ...
  • 之前對於synchronized的實現和運用有所瞭解,但是也發現了一些缺陷,由於synchronized是在JVM層面上實現同步互斥,是以關鍵字形式加鎖,導致其顆粒度過大,有的時候不需要這麼大範圍的加鎖,在中斷和線程阻塞處理上也有所欠缺,在JDK1.5之後,Java引入了Lock,作為對於synch ...
  • Django入門筆記 **文檔包含Django安裝包、學習的筆記、代碼等 安裝 Django參考附件,只需要把附件拷貝到你需要的目錄就行。Django是1.8.16版本 Python:在附件中,其中有Django需要的依賴包 編輯器:Aptana,一個強大的IDE工具,可以在上邊新建模板,支持各種語 ...
  • 異常處理 面向對象 迭代器和生成器 python異常處理 下麵代碼觸發了一個FileNotFoundError 拋出異常 異常類型 捕獲異常使用try,except,finally,else python面向對象 python是完全面向對象的,python中一切都是對象,包括變數,函數等。 定義一個 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...