當我們需要查詢companylist(對應company表), 但是資料又不僅僅只來自company表時,例如:我們還需要area表的省市區名稱時,可以這樣寫**會更優雅點(ps: 個人覺得)
1. companymodel(企業entity company對應的model)的定義
2. dao層介面的定義:
/*** 企業company表對應的model
* @description
* @author ***
* @date ***x年xx月xx日 上午10:50:00
*/public
@data
class
companymodel
extends
company
3. mybatis 自定義sql
/*** 通用的企業列表查詢
* @param queryparam : 查詢引數物件
* @return
*/listselectcompanylist
(companyqueryparam queryparam)
;
注:此處用 resulttype, companymodel物件繼承了company,mybatis返回查詢結果時用的是**物件, list可以指向list物件(父類引用指向子類物件類似於list a = new arraylist())
id="selectcompanylist"
resulttype="com.doubi.model.company.companymodel">
select a.* , b.province_name, b.city_name, b.area_name, b.street_name
from company a
left join sys_area b on b.id = a.zone_code
where true
test="level!=null">
test="level==2">
and left(a.area_id, 4)=left(#, 4)
if>
test="level==3">
and left(a.area_id, 6)=left(#, 6)
if>
test="level==4">
and left(a.area_id, 10)=left(#, 10)
if>
if>
test="name!= null">
and a.name= #
if>
select>
MyBatis動態sql查詢
什麼是動態sql mybatis核心 對sql語句進行靈活操作,通過表示式進行判斷,對sql進行靈活拼接 組裝。需求public class userpo if test userpo.id null and id if if where select id findusercount parame...
Mybatis 多條件動態查詢
例 簡單的乙個查詢 select from student tbl st where st.student name like concat concat 但是此時如果studentname是null或空字串,此語句很可能報錯或查詢結果為空。此時我們使用if動態sql語句先進行判斷,如果值為null...
mybatis 動態sql(查詢學習)
mybatis 這個框架 與書寫 sql 語句 有很大的關係,所以 在 沒有 sql 很好的 書寫能力下,會遇到好多問題,本人就是例子,先將學習 查詢操作中遇到的問題進行總結 一,標籤的使用,繫結上下文 多用與 sql 語句中 sql 語句like 模糊查詢使用 使用案列 select from s...