麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

總結一下工作中用到的Mybatis業務邏輯

2019-11-14 15:29:16
字體:
來源:轉載
供稿:網友

1.簡單說明。

  MyBatis 可以使用簡單的xml 或注解用于配置和原始映射,將接口和 java 的 POJO( Plain Old Java Objects,普通的Java 對象)映射成數據庫中的記錄。

  每一個MyBatis項目中都以一個對象sqlsessionFactory為核心,它可以通過sqlSessionFactoryBuilder來獲得,它產生了一個個的sqlSession。

2.關于項目中的使用做詳盡說明。

  什么是Mapper對象?根據Mybatis的官方手冊,應用程序除了要初始并啟動Mybatis之外,還需要定義一些接口,接口里定義訪問數據庫的方法,存放接口的包路徑下需要放置同名的XML配置文件。每個mapper元素對應一個mapper配置文件

3.Mybatis中參數傳遞的四種方式講解

  http://edu.51cto.com/index.php?do=lesson&id=69884

4.使用mybatis generator自動生成映射文件詳解

  http://www.companysz.com/mikelij/p/3841716.html  跟這篇一模一樣。

5.項目實例分析

 1 <?xml version="1.0" encoding="UTF-8" ?>   2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">   3 <mapper namespace="org.iMybatis.abc.dao.UserDao">   4     <cache type="PERPETUAL" eviction="LRU" flushInterval="60000"   5         size="512" readOnly="true" />   6     <resultMap id="userResultMap" type="UserDto">   7         <id PRoperty="userid" column="userid" />   8         <result property="username" column="username" />   9         <result property="passWord" column="password" />  10     </resultMap>  11     <sql id="userColumns"> userid,username,password </sql>  12     <select id="queryUsers" parameterType="UserDto" resultType="UserDto"  13         useCache="false">  14         select <include refid="userColumns" />  15         from t_user t where t.username = #{username}  16     </select>  17     <insert id="insertUser" parameterType="UserDto"  18         useGeneratedKeys="true" keyProperty="userid">  19         insert into t_user (userid,username,password)  20         values (#{userid},#{username},#{password})  21     </insert>  22     <update id="updateUser" parameterType="UserDto">  23         update t_user set  24         username= #{username},  25         password = #{password},  26         where userid = #{userid}  27     </update>  28     <delete id="deleteUser" parameterType="UserDto">  29         delete from t_user where userid = #{userid}  30     </delete>  31 </mapper>
一段熱乎乎的mapper的 XML 的配置文件

  看上面代碼,Mapper元素只有一個屬性namespace,它有兩個作用:一是用于區分不同的mapper(在不同的mapper文件里,子元素的id可以相同,mybatis通過namespace和子元素的id聯合區分),二是與接口關聯(應用程序通過接口訪問mybatis時,mybatis通過接口的完整名稱查找對應的mapper配置,因此namespace的命名務必小心一定要某接口同名)。此外,mapper配置文件還有幾個頂級子元素(它們須按照順序定義):cache -配置本定命名空間的緩存。resultMap –結果映射,用來描述如何從數據庫結果集映射到你想要的對象。接下來詳解一下resultMap。

<resultMap id="userResultMap" type="User">      <id property=" userid " column="userid" />      <result property="username" column="username" />      <result property="password" column="password" />  </resultMap> 
resultMap 配置

  resultMap提供了從數據庫表列名到java對象屬性的映射管理,示例只是提供了最簡單的情況。在mapper配置文件中可以配置多個resultMap,不同的resultMap用id加以區分。type屬性標記java類型(別名)。子元素中的property指帶java中的屬性,column指帶數據庫表的列名。

  Example類,用于構造復雜的篩選條件,詳細分析如下:

上面的sql語句,創建了表'order_detail',以及各個字段。

package redcliff.cobara.entity;import java.math.BigDecimal;public class CobaraOrderDetail {    private Long id;    private Integer cityId;    private Integer orderId;    private String name;    private Byte type;    private BigDecimal cost;    private Integer shardx;    private Integer shardy;    private Integer shardz;    public Long getId() {        return id;    }    public void setId(Long id) {        this.id = id;    }    public Integer getCityId() {        return cityId;    }    public void setCityId(Integer cityId) {        this.cityId = cityId;    }    public Integer getOrderId() {        return orderId;    }    public void setOrderId(Integer orderId) {        this.orderId = orderId;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name == null ? null : name.trim();    }    public Byte getType() {        return type;    }    public void setType(Byte type) {        this.type = type;    }    public BigDecimal getCost() {        return cost;    }    public void setCost(BigDecimal cost) {        this.cost = cost;    }    public Integer getShardx() {        return shardx;    }    public void setShardx(Integer shardx) {        this.shardx = shardx;    }    public Integer getShardy() {        return shardy;    }    public void setShardy(Integer shardy) {        this.shardy = shardy;    }    public Integer getShardz() {        return shardz;    }    public void setShardz(Integer shardz) {        this.shardz = shardz;    }}
redcliff.cobara.entity.CobaraOrderDetail.java

上面的entitiy包下的CobaraOrderDetail.java文件定義了實體類,是數據庫的各個字段在Java web項目中一模一樣的寫照。當然了它是mybatis的generator生成器自動生成的。注意到,結構public class CobaraOrderDetail;里面的變量定義為private類型,方法定義為public類型

package redcliff.cobara.entity;import java.math.BigDecimal;import java.util.ArrayList;import java.util.List;public class CobaraOrderDetailExample {    protected String orderByClause;    protected boolean distinct;    protected List<Criteria> oredCriteria;    public CobaraOrderDetailExample() {        oredCriteria = new ArrayList<Criteria>();    }    public void setOrderByClause(String orderByClause) {        this.orderByClause = orderByClause;    }    public String getOrderByClause() {        return orderByClause;    }    public void setDistinct(boolean distinct) {        this.distinct = distinct;    }    public boolean isDistinct() {        return distinct;    }    public List<Criteria> getOredCriteria() {        return oredCriteria;    }    public void or(Criteria criteria) {        oredCriteria.add(criteria);    }    public Criteria or() {        Criteria criteria = createCriteriaInternal();        oredCriteria.add(criteria);        return criteria;    }    public Criteria createCriteria() {        Criteria criteria = createCriteriaInternal();        if (oredCriteria.size() == 0) {            oredCriteria.add(criteria);        }        return criteria;    }    protected Criteria createCriteriaInternal() {        Criteria criteria = new Criteria();        return criteria;    }    public void clear() {        oredCriteria.clear();        orderByClause = null;        distinct = false;    }    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 andIdIsNull() {            addCriterion("id is null");            return (Criteria) this;        }        public Criteria andIdIsNotNull() {            addCriterion("id is not null");            return (Criteria) this;        }        public Criteria andIdEqualTo(Long value) {            addCriterion("id =", value, "id");            return (Criteria) this;        }        public Criteria andIdNotEqualTo(Long value) {            addCriterion("id <>", value, "id");            return (Criteria) this;        }        public Criteria andIdGreaterThan(Long value) {            addCriterion("id >", value, "id");            return (Criteria) this;        }        public Criteria andIdGreaterThanOrEqualTo(Long value) {            addCriterion("id >=", value, "id");            return (Criteria) this;        }        public Criteria andIdLessThan(Long value) {            addCriterion("id <", value, "id");            return (Criteria) this;        }        public Criteria andIdLessThanOrEqualTo(Long value) {            addCriterion("id <=", value, "id");            return (Criteria) this;        }        public Criteria andIdIn(List<Long> values) {            addCriterion("id in", values, "id");            return (Criteria) this;        }        public Criteria andIdNotIn(List<Long> values) {            addCriterion("id not in", values, "id");            return (Criteria) this;        }        public Criteria andIdBetween(Long value1, Long value2) {            addCriterion("id between", value1, value2, "id");            return (Criteria) this;        }        public Criteria andIdNotBetween(Long value1, Long value2) {            addCriterion("id not between", value1, value2, "id");            return (Criteria) this;        }        public Criteria andCityIdIsNull() {            addCriterion("city_id is null");            return (Criteria) this;        }        public Criteria andCityIdIsNotNull() {            addCriterion("city_id is not null");            return (Criteria) this;        }        public Criteria andCityIdEqualTo(Integer value) {            addCriterion("city_id =", value, "cityId");            return (Criteria) this;        }        public Criteria andCityIdNotEqualTo(Integer value) {            addCriterion("city_id <>", value, "cityId");            return (Criteria) this;        }        public Criteria andCityIdGreaterThan(Integer value) {            addCriterion("city_id >", value, "cityId");            return (Criteria) this;        }        public Criteria andCityIdGreaterThanOrEqualTo(Integer value) {            addCriterion("city_id >=", value, "cityId");            return (Criteria) this;        }        public Criteria andCityIdLessThan(Integer value) {            addCriterion("city_id <", value, "cityId");            return (Criteria) this;        }        public Criteria andCityIdLessThanOrEqualTo(Integer value) {            addCriterion("city_id <=", value, "cityId");            return (Criteria) this;        }        public Criteria andCityIdIn(List<Integer> values) {            addCriterion("city_id in", values, "cityId");            return (Criteria) this;        }        public Criteria andCityIdNotIn(List<Integer> values) {            addCriterion("city_id not in", values, "cityId");            return (Criteria) this;        }        public Criteria andCityIdBetween(Integer value1, Integer value2) {            addCriterion("city_id between", value1, value2, "cityId");            return (Criteria) this;        }        public Criteria andCityIdNotBetween(Integer value1, Integer value2) {            addCriterion("city_id not between", value1, value2, "cityId");            return (Criteria) this;        }        public Criteria andOrderIdIsNull() {            addCriterion("order_id is null");            return (Criteria) this;        }        public Criteria andOrderIdIsNotNull() {            addCriterion("order_id is not null");            return (Criteria) this;        }        public Criteria andOrderIdEqualTo(Integer value) {            addCriterion("order_id =", value, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdNotEqualTo(Integer value) {            addCriterion("order_id <>", value, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdGreaterThan(Integer value) {            addCriterion("order_id >", value, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdGreaterThanOrEqualTo(Integer value) {            addCriterion("order_id >=", value, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdLessThan(Integer value) {            addCriterion("order_id <", value, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdLessThanOrEqualTo(Integer value) {            addCriterion("order_id <=", value, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdIn(List<Integer> values) {            addCriterion("order_id in", values, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdNotIn(List<Integer> values) {            addCriterion("order_id not in", values, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdBetween(Integer value1, Integer value2) {            addCriterion("order_id between", value1, value2, "orderId");            return (Criteria) this;        }        public Criteria andOrderIdNotBetween(Integer value1, Integer value2) {            addCriterion("order_id not between", value1, value2, "orderId");            return (Criteria) this;        }        public Criteria andNameIsNull() {            addCriterion("name is null");            return (Criteria) this;        }        public Criteria andNameIsNotNull() {            addCriterion("name is not null");            return (Criteria) this;        }        public Criteria andNameEqualTo(String value) {            addCriterion("name =", value, "name");            return (Criteria) this;        }        public Criteria andNameNotEqualTo(String value) {            addCriterion("name <>", value, "name");            return (Criteria) this;        }        public Criteria andNameGreaterThan(String value) {            addCriterion("name >", value, "name");            return (Criteria) this;        }        public Criteria andNameGreaterThanOrEqualTo(String value) {            addCriterion("name >=", value, "name");            return (Criteria) this;        }        public Criteria andNameLessThan(String value) {            addCriterion("name <", value, "name");            return (Criteria) this;        }        public Criteria andNameLessThanOrEqualTo(String value) {            addCriterion("name <=", value, "name");            return (Criteria) this;        }        public Criteria andNameLike(String value) {            addCriterion("name like", value, "name");            return (Criteria) this;        }        public Criteria andNameNotLike(String value) {            addCriterion("name not like", value, "name");            return (Criteria) this;        }        public Criteria andNameIn(List<String> values) {            addCriterion("name in", values, "name");            return (Criteria) this;        }        public Criteria andNameNotIn(List<String> values) {            addCriterion("name not in", values, "name");            return (Criteria) this;        }        public Criteria andNameBetween(String value1, String value2) {            addCriterion("name between", value1, value2, "name");            return (Criteria) this;        }        public Criteria andNameNotBetween(String value1, String value2) {            addCriterion("name not between", value1, value2, "name");            return (Criteria) this;        }        public Criteria andTypeIsNull() {            addCriterion("type is null");            return (Criteria) this;        }        public Criteria andTypeIsNotNull() {            addCriterion("type is not null");            return (Criteria) this;        }        public Criteria andTypeEqualTo(Byte value) {            addCriterion("type =", value, "type");            return (Criteria) this;        }        public Criteria andTypeNotEqualTo(Byte value) {            addCriterion("type <>", value, "type");            return (Criteria) this;        }        public Criteria andTypeGreaterThan(Byte value) {            addCriterion("type >", value, "type");            return (Criteria) this;        }        public Criteria andTypeGreaterThanOrEqualTo(Byte value) {            addCriterion("type >=", value, "type");            return (Criteria) this;        }        public Criteria andTypeLessThan(Byte value) {            addCriterion("type <", value, "type");            return (Criteria) this;        }        public Criteria andTypeLessThanOrEqualTo(Byte value) {            addCriterion("type <=", value, "type");            return (Criteria) this;        }        public Criteria andTypeIn(List<Byte> values) {            addCriterion("type in", values, "type");            return (Criteria) this;        }        public Criteria andTypeNotIn(List<Byte> values) {            addCriterion("type not in", values, "type");            return (Criteria) this;        }        public Criteria andTypeBetween(Byte value1, Byte value2) {            addCriterion("type between", value1, value2, "type");            return (Criteria) this;        }        public Criteria andTypeNotBetween(Byte value1, Byte value2) {            addCriterion("type not between", value1, value2, "type");            return (Criteria) this;        }        public Criteria andCostIsNull() {            addCriterion("cost is null");            return (Criteria) this;        }        public Criteria andCostIsNotNull() {            addCriterion("cost is not null");            return (Criteria) this;        }        public Criteria andCostEqualTo(BigDecimal value) {            addCriterion("cost =", value, "cost");            return (Criteria) this;        }        public Criteria andCostNotEqualTo(BigDecimal value) {            addCriterion("cost <>", value, "cost");            return (Criteria) this;        }        public Criteria andCostGreaterThan(BigDecimal value) {            addCriterion("cost >", value, "cost");            return (Criteria) this;        }        public Criteria andCostGreaterThanOrEqualTo(BigDecimal value) {            addCriterion("cost >=", value, "cost");            return (Criteria) this;        }        public Criteria andCostLessThan(BigDecimal value) {            addCriterion("cost <", value, "cost");            return (Criteria) this;        }        public Criteria andCostLessThanOrEqualTo(BigDecimal value) {            addCriterion("cost <=", value, "cost");            return (Criteria) this;        }        public Criteria andCostIn(List<BigDecimal> values) {            addCriterion("cost in", values, "cost");            return (Criteria) this;        }        public Criteria andCostNotIn(List<BigDecimal> values) {            addCriterion("cost not in", values, "cost");            return (Criteria) this;        }        public Criteria andCostBetween(BigDecimal value1, BigDecimal value2) {            addCriterion("cost between", value1, value2, "cost");            return (Criteria) this;        }        public Criteria andCostNotBetween(BigDecimal value1, BigDecimal value2) {            addCriterion("cost not between", value1, value2, "cost");            return (Criteria) this;        }        public Criteria andShardxIsNull() {            addCriterion("shardx is null");            return (Criteria) this;        }        public Criteria andShardxIsNotNull() {            addCriterion("shardx is not null");            return (Criteria) this;        }        public Criteria andShardxEqualTo(Integer value) {            addCriterion("shardx =", value, "shardx");            return (Criteria) this;        }        public Criteria andShardxNotEqualTo(Integer value) {            addCriterion("shardx <>", value, "shardx");            return (Criteria) this;        }        public Criteria andShardxGreaterThan(Integer value) {            addCriterion("shardx >", value, "shardx");            return (Criteria) this;        }        public Criteria andShardxGreaterThanOrEqualTo(Integer value) {            addCriterion("shardx >=", value, "shardx");            return (Criteria) this;        }        public Criteria andShardxLessThan(Integer value) {            addCriterion("shardx <", value, "shardx");            return (Criteria) this;        }        public Criteria andShardxLessThanOrEqualTo(Integer value) {            addCriterion("shardx <=", value, "shardx");            return (Criteria) this;        }        public Criteria andShardxIn(List<Integer> values) {            addCriterion("shardx in", values, "shardx");            return (Criteria) this;        }        public Criteria andShardxNotIn(List<Integer> values) {            addCriterion("shardx not in", values, "shardx");            return (Criteria) this;        }        public Criteria andShardxBetween(Integer value1, Integer value2) {            addCriterion("shardx between", value1, value2, "shardx");            return (Criteria) this;        }        public Criteria andShardxNotBetween(Integer value1, Integer value2) {            addCriterion("shardx not between", value1, value2, "shardx");            return (Criteria) this;        }        public Criteria andShardyIsNull() {            addCriterion("shardy is null");            return (Criteria) this;        }        public Criteria andShardyIsNotNull() {            addCriterion("shardy is not null");            return (Criteria) this;        }        public Criteria andShardyEqualTo(Integer value) {            addCriterion("shardy =", value, "shardy");            return (Criteria) this;        }        public Criteria andShardyNotEqualTo(Integer value) {            addCriterion("shardy <>", value, "shardy");            return (Criteria) this;        }        public Criteria andShardyGreaterThan(Integer value) {            addCriterion("shardy >", value, "shardy");            return (Criteria) this;        }        public Criteria andShardyGreaterThanOrEqualTo(Integer value) {            addCriterion("shardy >=", value, "shardy");            return (Criteria) this;        }        public Criteria andShardyLessThan(Integer value) {            addCriterion("shardy <", value, "shardy");            return (Criteria) this;        }        public Criteria andShardyLessThanOrEqualTo(Integer value) {            addCriterion("shardy <=", value, "shardy");            return (Criteria) this;        }        public Criteria andShardyIn(List<Integer> values) {            addCriterion("shardy in", values, "shardy");            return (Criteria) this;        }        public Criteria andShardyNotIn(List<Integer> values) {            addCriterion("shardy not in", values, "shardy");            return (Criteria) this;        }        public Criteria andShardyBetween(Integer value1, Integer value2) {            addCriterion("shardy between", value1, value2, "shardy");            return (Criteria) this;        }        public Criteria andShardyNotBetween(Integer value1, Integer value2) {            addCriterion("shardy not between", value1, value2, "shardy");            return (Criteria) this;        }        public Criteria andShardzIsNull() {            addCriterion("shardz is null");            return (Criteria) this;        }        public Criteria andShardzIsNotNull() {            addCriterion("shardz is not null");            return (Criteria) this;        }        public Criteria andShardzEqualTo(Integer value) {            addCriterion("shardz =", value, "shardz");            return (Criteria) this;        }        public Criteria andShardzNotEqualTo(Integer value) {            addCriterion("shardz <>", value, "shardz");            return (Criteria) this;        }        public Criteria andShardzGreaterThan(Integer value) {            addCriterion("shardz >", value, "shardz");            return (Criteria) this;        }        public Criteria andShardzGreaterThanOrEqualTo(Integer value) {            addCriterion("shardz >=", value, "shardz");            return (Criteria) this;        }        public Criteria andShardzLessThan(Integer value) {            addCriterion("shardz <", value, "shardz");            return (Criteria) this;        }        public Criteria andShardzLessThanOrEqualTo(Integer value) {            addCriterion("shardz <=", value, "shardz");            return (Criteria) this;        }        public Criteria andShardzIn(List<Integer> values) {            addCriterion("shardz in", values, "shardz");            return (Criteria) this;        }        public Criteria andShardzNotIn(List<Integer> values) {            addCriterion("shardz not in", values, "shardz");            return (Criteria) this;        }        public Criteria andShardzBetween(Integer value1, Integer value2) {            addCriterion("shardz between", value1, value2, "shardz");            return (Criteria) this;        }        public Criteria andShardzNotBetween(Integer value1, Integer value2) {            addCriterion("shardz not between", value1, value2, "shardz");            return (Criteria) this;        }    }    public static class Criteria extends GeneratedCriteria {        protected Criteria() {            super();        }    }    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);        }    }}
redcliff.cobara.entity.CobaraOrderDetailExample.java

上面的entity包下的CobaraOrderDetailExample.java文件同樣也是用于映射的。只不過它用于構造復雜的篩選條件。注意到,里面的變量定義為protected類型,方法定義為public類型;結構public class CobaraOrderDetailExample。兩個Java類獨立存在,不相互依存。

package redcliff.cobara.mapper;import com.dianwoba.redcliff.cobara.entity.CobaraOrderDetail;import com.dianwoba.redcliff.cobara.entity.CobaraOrderDetailExample;import java.util.List;import org.apache.ibatis.annotations.Param;public interface CobaraOrderDetailMapper {    int countByExample(CobaraOrderDetailExample example);    int deleteByExample(CobaraOrderDetailExample example);    int deleteByPrimaryKey(Long id);    int insert(CobaraOrderDetail record);    int insertSelective(CobaraOrderDetail record);    List<CobaraOrderDetail> selectByExample(CobaraOrderDetailExample example);    CobaraOrderDetail selectByPrimaryKey(Long id);    int updateByExampleSelective(@Param("record") CobaraOrderDetail record, @Param("example") CobaraOrderDetailExample example);    int updateByExample(@Param("record") CobaraOrderDetail record, @Param("example") CobaraOrderDetailExample example);    int updateByPrimaryKeySelective(CobaraOrderDetail record);    int updateByPrimaryKey(CobaraOrderDetail record);}
redcliff.cobara.mapper.CobaraOrderDetailMapper.java

上面的mapper包下的CobaraOrderDetailMapper.java類中,定義了基于類CobaraOrderDetailExample的CRUD方法。從結構public interface CobarOrderDetailExample上來看,當然是沒有實現的。

package redcliff.cobara.mapper;public interface CobaraOrderDetailMapperExt extends CobaraOrderDetailMapper {}
redcliff.cobara.mapper.CobaraOrderDetailMapperExt.java

上面的mapper包下的CobaraOrderDetailMapperExt.java類中,是一個空的接口。從結構上來看public interface CobaraOrderDetailMapperExt  extends CobaraOrderDetailMapper。從名字上來看Ext是英文單詞external的簡寫,'external'的本意是外部的,外面的簡寫。可見此類是用于擴展的。

redcliff.cobara.mapper.CobaraOrderDetailMapper.xml

上面的redcliff.cobara.mapper.CobaraOrderDetailMapperExt.xml映射文件定義了基本的CRUD四個方法。

<?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="redcliff.cobara.mapper.CobaraOrderDetailMapperExt" >  </mapper>
redcliff.cobara.mapper.CobaraOrderDetailMapperExt.xml

上面的redcliff.cobara.mapper.CobaraOrderDetailMapperExt.xml映射文件,擴展了CRUD操作,因為從mapper標簽的唯一屬性namespace兩個xml是完全一樣的。

以上的這些代碼,用一句話描述就是:“entity.java建立了與數據庫的映射,mapper.java中定義了CRUD的方法,mapper.xml中實現了方法”,那么他們是怎么聯系起來的呢?mapper.java中的方法接收的參數是entityExample(半成品的sql語句)。mapper標簽的namespace指示到了mapper.java類,意思是我對你的方法進行了實現。

附錄,補充

 學習資料參考地址


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美日韩亚洲另类 | 国产一区日韩一区 | 日本a大片 | www.91视频com| 久久国产一级 | 毛片118极品美女写真 | 国产成人羞羞视频在线 | 暴力肉体进入hdxxxx0 | 国产午夜探花 | 99精品视频久久精品视频 | 毛片在线免费视频 | hdbbwsexvideo| 色视频一区二区 | 草草视频免费 | 综合在线视频 | 国产手机国产手机在线 | 成人免费福利网站 | 欧美日韩手机在线观看 | 午夜在线视频观看 | 久久亚洲精品久久国产一区二区 | 国产精品99久久久久久董美香 | 欧美亚洲国产一区二区三区 | 成人免费网站在线观看视频 | 中文日韩在线 | 国产精品一区二区三区在线 | 色妹子久久 | 日本一区二区视频在线观看 | 午夜视 | 一级黄色国产视频 | 欧美 videos粗暴| 在线播放黄色网址 | 久久成人亚洲 | 特大黑人videos与另类娇小 | 国产1区视频 | 渔夫荒淫艳史 | 免费a级毛片大学生免费观看 | 国产成人高清在线观看 | 久久国产精品久久精品国产演员表 | 九九热在线视频免费观看 | 国产精品免费视频观看 | 日韩黄在线观看 |