求SpringMvc+mybatis的通用dao层编写

2025-02-25 21:37:04
推荐回答(1个)
回答1:

mybatis是没有通用dao层的,都要一个方法写一个sql语句例如:

//先写一个dao接口
public interface CustomerDao
{

Map getUserByAccounts(String accounts);

Map getUserDetailById(int id);

void lossAccountsByUserId(String userId);

PageList> getCanReversedList(Map queMap);

PageList> searchAccountsAnomaly(Map param);

Map isHasAccounts(String accounts);

void accountsRecover(Map updateInfo);

}
//在写一个dao的xml文件






select * from apdp_user a where UPPER(a.username)=UPPER(#{accounts})



select u.id,u.id_card,u.bind_phone from kc_user_detail u where u.id=#{id}



select k.*,k2.app_time as CZ_TIME,k2.DISCOUNT_FEE as REVERSED_FEE from kc_phone_charge_app k left join
(select * from kc_phone_charge_app a where a.type_id=2) k2 on
k.reversed_app_id=k2.id 

left join apdp_user u on k.app_user_id=u.id

where k.app_time > (SYSDATE -3) and k.TYPE_ID=1

and k.CHARGE_PHONE_NO like #{CHARGE_PHONE_NO}||'%' 


and k.SEQ_CODE like #{SEQ_CODE}||'%' 


and to_char(k.APP_TIME,'yyyy-MM-dd') >= #{rechargeDate1} 
]]>


and to_char(k.APP_TIME,'yyyy-MM-dd') <= #{rechargeDate2} 
]]>


and to_char(k2.APP_TIME,'yyyy-MM-dd') >= #{acceptDate1} 
]]>


and to_char(k2.APP_TIME,'yyyy-MM-dd') <= #{acceptDate2} 
]]>


and upper(u.USERNAME) like upper(#{userCode}||'%') 


and k.APP_USER_NAME like '%'||#{userName}||'%'

order by k.app_time DESC



select a.*,u.realname unlockUser from KC_ACCOUNT_ANOMALY a left join
apdp_user u on a.unlock_user=u.id where
upper(a.user_accounts)=upper(#{accounts}) order by a.anomaly_time DESC



select * from apdp_user u where upper(u.username)=upper(#{accounts})



update apdp_user a set a.accountloss='1' where a.id=#{userId}



update kc_account_anomaly a set a.unlock_time=SYSDATE,a.unlock_user=#{userId},a.status=0 where a.id=#{id}


建议你去百度文库直接搜mybatis的教程资料,有更加详细的解释和例子