国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

醫(yī)院網站建設 費用百度認證官網

醫(yī)院網站建設 費用,百度認證官網,wordpress不同分類目錄顯示文章數量不同,怎么做廢品網站resultMap 表示查詢結果集與java對象之間的一種關系,處理查詢結果集,映射到java對象。 resultMap 是一種“查詢結果集---Bean對象”屬性名稱映射關系,使用resultMap關系可將將查詢結果集中的列一一映射到bean對象的各個屬性&#…

resultMap? ? ??


? ? 表示查詢結果集與java對象之間的一種關系,處理查詢結果集,映射到java對象。 ? ??

? ? ? ?resultMap 是一種“查詢結果集---Bean對象”屬性名稱映射關系,使用resultMap關系可將將查詢結果集中的列一一映射到bean對象的各個屬性(兩者屬性名可以不同,配置好映射關系即可),適用與復雜一點的查詢。

(1)適用于表的連接查詢(在resultMap里面可以配置連接條件,見如下程序association標簽)
?

<!-- 訂單查詢關聯用戶的resultMap將整個查詢的結果映射到cn.itcast.mybatis.po.Orders中   -->  <resultMap type="cn.itcast.mybatis.po.Orders" id="OrdersUserResultMap">  <!-- 配置映射的訂單信息 -->  <!-- id:指定查詢列中的唯 一標識,訂單信息的中的唯 一標識,如果有多個列組成唯一標識,配置多個id ,column:訂單信息的唯 一標識列 ,property:訂單信息的唯 一標識 列所映射到Orders中哪個屬性  -->  <id column="id" property="id"/><result column="user_id" property="userId"/> <result column="number" property="number"/> <result column="createtime" property="createtime"/><result column="note" property=note/>          <!-- 配置映射的關聯的用戶信息 --> <!-- association:用于映射關聯查詢單個對象的信息property:要將關聯查詢的用戶信息映射到Orders中哪個屬性 -->  <association property="user"  javaType="cn.itcast.mybatis.po.User"><!-- id:關聯查詢用戶的唯 一標識column:指定唯 一標識用戶信息的列javaType:映射到user的哪個屬性--><id column="user_id" property="id"/><result column="username" property="username"/><result column="sex" property="sex"/><result column="address" property="address"/></association> </resultMap>

2)適用于表的一對多連接查詢,(如,訂單對應多個訂單明細時,需要根據連接條件訂單id匹配訂單明細,并且消除重復的訂單信息(訂單明細中的),如下程序);

<resultMap type="cn.itcast.mybatis.po.Orders" id="OrdersAndOrderDetailResultMap" extends="OrdersUserResultMap"><!-- 訂單信息 --> <!-- 用戶信息 --><!-- 使用extends繼承,不用在中配置訂單信息和用戶信息的映射 --><!-- 訂單明細信息一個訂單關聯查詢出了多條明細,要使用collection進行映射collection:對關聯查詢到多條記錄映射到集合對象中property:將關聯查詢到多條記錄映射到cn.itcast.mybatis.po.Orders哪個屬性 ofType:指定映射到list集合屬性中pojo的類型 -->  <collection property="orderdetails" ofType="cn.itcast.mybatis.po.Orderdetail"><!-- id:訂單明細唯 一標識 property:要將訂單明細的唯 一標識 映射到cn.itcast.mybatis.po.Orderdetail的哪個屬性-->  <id column="orderdetail_id" property="id"/><result column="items_id" property="itemsId"/><result column="items_num" property="itemsNum"/><result column="orders_id" property="ordersId"/></collection></resultMap> 

(3)映射的查詢結果集中的列標簽可以根據需要靈活變化,并且,在映射關系中,還可以通過typeHandler設置實現查詢結果值的類型轉換,比如布爾型與0/1的類型轉換。

例如:

<resultMap type="hdu.terence.bean.Message" id="MessageResult"> <!--存放Dao值--><!--type是和數據庫對應的bean類名Message--><id column="id" jdbcType="INTEGER"property=" id"/><!--主鍵標簽--><result column="COMMAND" jdbcType="VARCHAR" property="command"/><result column="DESCRIPTION" jdbcType="VARCHAR" property="description"/><result column="CONTENT" jdbcType="VARCHAR" property="content"/></resultMap> <select id="queryMessageList" parameterType="hdu.terence.bean.Message" resultMap="MessageResult">SELECTID,COMMAND,DESCRIPTION,CONTENT FROM message WHERE 1=1    <if test="command!=null and!&quot;&quot;.equals(command.trim())">and COMMAND=#{command}</if><if test="description!=null and!&quot;&quot;.equals(description.trim())">and DESCRIPTION like '%' #{description} '%'</if> </select>

resultType

resultType 是一種“查詢結果集---Bean對象”數據類型映射關系,使用resultType關系,即可使Bean對象接收查詢結果集;見名知意,該方法是通過查詢結果集中每條記錄(屬性)的數據類型和Bean對象的數據類型作映射,若兩者都相同,則表示匹配成功,Bean可以接收到查詢結果。

? ?但是本方法有局限性,要求Bean對象字段名和查詢結果集的屬性名相同(可以大小寫不同,大小寫不敏感)。因為這個局限性,可以省略調resultMap進行屬性名映射。

? ? 一般適用于pojo(簡單對象)類型數據,簡單的單表查詢。

? ?以下是resultType的寫法,將其值設置成對應的java類上即可。不需要上述resultMap的映射關系。

<select resultType="User" id="findAll">select *from user </select>
<select resultType="com.itxiaotong.pojo.User" id="findById" parameterType="int">select *from user where id = #{userId} </select>
<select resultType="com.itxiaotong.pojo.User" id="findByUsernameLike" parameterType="string">
<bind value="'%'+username+'%'" name="likeName"/>
select * from user where username like #{likeName} 
</select>
<select resultType="com.itxiaotong.pojo.User" id="findPage">select * from user limit #{param1},#{param2} </select><select resultType="com.itxiaotong.pojo.User" id="findPage1">select * from user limit #{startIndex},#{pageSize} </select>
<select resultType="User" id="findPage2" parameterType="PageQuery">select * from user limit #{startIndex},#{pageSize} </select>

其中parameterType="PageQuery"的類是,下列內容

PageQuery.java

package com.itxiaotong.pojo;public class PageQuery {private int startIndex;private int pageSize;public PageQuery() {}public PageQuery(int startIndex, int pageSize) {this.startIndex = startIndex;this.pageSize = pageSize;}public int getStartIndex() {return startIndex;}public void setStartIndex(int startIndex) {this.startIndex = startIndex;}public int getPageSize() {return pageSize;}public void setPageSize(int pageSize) {this.pageSize = pageSize;}
}
<select resultType="com.itxiaotong.pojo.User" id="findPage3" parameterType="map">select * from user limit #{startIndex},#{pageSize} </select><select resultType="int" id="findCount">select count(id) from user </select>

parameterType

在mybatis映射接口的配置中,有select,insert,update,delete等元素都提到了
parameterType的用法,parameterType為輸入參數,在配置的時候,配置相應的
輸入參數類型即可。parameterType有基本數據類型和復雜的數據類型配置。
1.基本數據類型,如輸入參數只有一個,其數據類型可以是基本的數據類型,也可以是
自己定的類類型。包括int,String,Integer,Date,如下:

(1)根據id進行相應的刪除:

(2)添加員工:

2.復雜數據類型:包含java實體類,map。


parameterType例子(一)

?現在有一個Mapper配置文件,以下是片段:

 <select id="queryCommandListByPage" resultMap="CommandResult" >select <include refid="columns"/> from command a left join command_content b on a.id=b.command_id<where><if test="command.name != null and !"".equals(command.name.trim())">and a.name=#{command.name}</if><if test="command.description != null and !"".equals(command.description.trim())">and a.description like '%' #{command.description} '%'</if></where><if test="flag==1">group by aid</if>order by id</select><sql  id="columns">a.id aid,a.name,a.description,b.content,b.id,b.command_id</sql>

下面是IService接口:

 /*** 攔截器實現分頁*/public List<command> queryCommandListByPage(Map<String,Object>parameter);

parameterType例子(二)

<insert id="add" parameterType="com.itxiaotong.pojo.User">insert into user(username, sex, address)values (#{username}, #{sex}, #{address}) </insert>
<update id="update" parameterType="com.itxiaotong.pojo.User">update user set username = #{username},sex = #{sex},address=#{address} where id = #{id} </update>
<delete id="delete" parameterType="int">delete from user where id = #{id} </delete>
<insert id="add2" parameterType="com.itxiaotong.pojo.User"><!-- keyProperty:主鍵屬性名 keyColumn:主鍵列名 resultType:主鍵類型 order:執(zhí)行時機 --><selectKey resultType="int" order="AFTER" keyColumn="id" keyProperty="id">SELECT LAST_INSERT_ID(); </selectKey>
insert into user(username, sex, address)values (#{username}, #{sex}, #{address}) 
</insert>
<select resultType="com.itxiaotong.pojo.User" id="findPage3" parameterType="map">select * from user limit #{startIndex},#{pageSize} </select>

http://m.aloenet.com.cn/news/42712.html

相關文章:

  • 四川建設廳官方網站四庫一平臺網絡運營商
  • 建設銀行手機查詢網站合肥seo優(yōu)化排名公司
  • 在北京大學生做家教的網站關鍵詞調詞平臺哪個好
  • 東莞電商頁面設計公司福州短視頻seo機會
  • 杭州網站建設wguser域名歸屬查詢
  • 優(yōu)秀網站頁面設計圖片蘭州模板網站seo價格
  • 直播網站怎么做站長工具百度百科
  • 網站建好了怎么做淘寶客seo指導
  • 偽類網站hyein seo官網
  • 網站 關于我們 模板免費網絡營銷推廣軟件
  • 網站開發(fā)都需要學什么深圳搜索競價賬戶托管
  • java企業(yè)網站商丘seo博客
  • 如何購買網站俄羅斯搜索引擎瀏覽器
  • 網頁制作圖片模板整站seo排名外包
  • 百度搜索優(yōu)化建議seo的基礎優(yōu)化
  • 網站都是什么軟件做的百度營銷推廣
  • 賀州網絡推廣青島seo建站
  • 做翻糖的網站百度分公司
  • seo網站建設微域名解析網站
  • 寶安網站設計排名網店代運營騙局流程
  • 京東網站建設百度高級搜索網址
  • 哪個軟件做網站最簡單長沙專業(yè)競價優(yōu)化首選
  • 安卓手機app下載網站優(yōu)化種類
  • 網站標題特殊符號長沙百度快速優(yōu)化排名
  • asp net做網站視頻購物網站哪個最好
  • 做雜志的模板下載網站有哪些貴陽百度推廣電話
  • 網站交互效果網絡營銷的步驟
  • 廈門國外網站建設公司廣州競價托管代運營
  • 深圳網站建設找哪家好中視頻自媒體平臺注冊
  • iis網站重定向設置百度寧波營銷中心