mybatis的xml中使用@符號(hào)調(diào)用類方法示例
兩種方式
我們可以在mybatis的xml中通過(guò)@符合的方式調(diào)用Java類獲得返回值進(jìn)行操作,兩種方式
1、調(diào)用類靜態(tài)方法
調(diào)用類的靜態(tài)方法:"@類全路徑@方法名(入?yún)?" 如 "@com.modules.api.controller.UsersController@testStatic()"
示例xml
<select id="test" resultType="com.modules.user.entity.StUsers">
select * from st_users where id = 7000
<if test="@com.modules.api.controller.UsersController@testStatic()">
or id = 7001
</if>
</select>被調(diào)用方法
粗體
public static boolean testStatic() {
return true;
}日志輸出sql 確實(shí)拼接了or的sql
JDBC Connection [com.mysql.jdbc.JDBC4Connection@189690a6] will not be managed by Spring ==> Preparing: select * from st_users where id = 7000 or id = 7001 ==> Parameters:
2. 使用spring依賴注入的方式
例如 #{#deptName} IN ( #{@sdss.getDeptAndChild( #user.deptId )} ) 其中 @sdss 是spring容器中的bean名稱 后面就是點(diǎn)方法傳入?yún)?/p>
示例
/**
* 數(shù)據(jù)權(quán)限 實(shí)現(xiàn)
*/
@Service("sdss")
public class SysDataScopeService {
public boolean testStatic() {
return true;
}
}xml
<select id="test" resultType="com.modules.user.entity.StUsers">
select * from st_users where id = 7000
<if test="@sdss@testStatic()">
or id = 7001
</if>
</select>以上就是mybatis的xml中使用@符號(hào)調(diào)用類方法示例的詳細(xì)內(nèi)容,更多關(guān)于mybatis xml使用@調(diào)用類的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java @PostMapping和@GetMapping方法使用詳解
這篇文章主要介紹了Java @PostMapping和@GetMapping方法使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-03-03
java+jsp+struts2實(shí)現(xiàn)發(fā)送郵件功能
這篇文章主要為大家詳細(xì)介紹了java+jsp+struts2實(shí)現(xiàn)發(fā)送郵件功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03
Feign遠(yuǎn)程調(diào)用丟失請(qǐng)求頭問(wèn)題
本文介紹了在服務(wù)端項(xiàng)目中如何解決資源訪問(wèn)限制問(wèn)題,首先介紹了問(wèn)題的產(chǎn)生,然后詳細(xì)解析了源碼,最后提出了解決方案,解決方案包括同步和異步兩種,同步時(shí)直接向Spring容器注入RequestInterceptor攔截器2024-09-09

