日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mybatis:延迟加载时不要在get/set方法上面添加final关键字(原创)

發布時間:2023/12/18 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mybatis:延迟加载时不要在get/set方法上面添加final关键字(原创) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.mybatis-config.xml:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-config.dtd"> <configuration> <settings> <setting name="lazyLoadingEnabled" value="true"/> <setting name="aggressiveLazyLoading" value="false"/> </settings> </configuration>

以上延遲加載配置是有效的。

#全局啟用或禁用延遲加載。當禁用時,所有關聯對象都會即時加載。 mybatis.configuration.lazy-loading-enabled=true #當啟用時,有延遲加載屬性的對象在被調用時將會完全加載任意屬性。否則,每種屬性將會按需要加載。 mybatis.configuration.aggressive-lazy-loading=false

這是我在springboot中的配置,發現沒有作用,請用文件方式的配置

2.Mapper文件配置

<mapper namespace="com.test.dao.base.DaoBaseUser"><resultMap id="BaseResultMap"type="com.test.entity.base.EntityBaseUser"><id column="userID" jdbcType="VARCHAR" property="userID" /><result column="orgID" jdbcType="VARCHAR" property="orgID" /><result column="postID" jdbcType="VARCHAR" property="postID" /> <!-- 關聯查詢:用戶對應的角色 --><association property="roles" javaType="java.util.List" select="com.csget.dao.base.DaoBaseUser.selectRoles" column="userID"/></resultMap><select id="selectRoles" resultType="java.lang.String">SELECT roleID FROM t_base_role_user_ref WHERE userID=#{userID}</select><select id="selectByMobile" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from t_base_user where mobile=#{mobile} and isValid='1' </select> </mapper>

3.get/set方法

public class EntityBaseUser{
//其它屬性省略 /*** 獲得:用戶的角色列表** @return the roles*/public final List<String> getRoles() {return roles;}/*** 設置:用戶的角色列表** @param roles* the roles to set*/public final void setRoles(List<String> roles) {this.roles = roles;} }

發現調用getRoles()方法并沒有觸發延遲加載查詢,當斷點調試的時候,鼠標放到EntityBaseUser的實例變量上,會立刻觸發延遲加載查詢,真是很奇怪。

最后懷疑:是不是get/set方法上面加了final導致的,果然去掉之后,發現一切正常了。

轉載于:https://www.cnblogs.com/huiy/p/9278767.html

總結

以上是生活随笔為你收集整理的mybatis:延迟加载时不要在get/set方法上面添加final关键字(原创)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。