亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

mybatis 多對多 在collection中使用select查詢報錯。。求解

mybatis 多對多 在collection中使用select查詢報錯。。求解

慕粉4241372 2017-08-23 10:09:04
website類public?class?Website?{ ????private?Integer?id; ????private?String?name; ????private?String?websiteAddress; ????private?List<Category>?categoryList; ????private?List<Score>?scoreList; ????public?Website()?{ ????????super(); ????} ????public?Integer?getId()?{ ????????return?id; ????} ????public?void?setId(Integer?id)?{ ????????this.id?=?id; ????} ????public?String?getName()?{ ????????return?name; ????} ????public?void?setName(String?name)?{ ????????this.name?=?name?==?null???null?:?name.trim(); ????} ????public?String?getWebsiteAddress()?{ ????????return?websiteAddress; ????} ????public?void?setWebsiteAddress(String?websiteAddress)?{ ????????this.websiteAddress?=?websiteAddress?==?null???null?:?websiteAddress.trim(); ????} ????public?List<Category>?getCategoryList()?{ ????????return?categoryList; ????} ????public?void?setCategoryList(List<Category>?categoryList)?{ ????????this.categoryList?=?categoryList; ????} ????public?List<Score>?getScoreList()?{ ????????return?scoreList; ????} ????public?void?setScoreList(List<Score>?scoreList)?{ ????????this.scoreList?=?scoreList; ????} }category類public?class?Category?{ ????private?Integer?id; ????private?String?name; ????private?Integer?parentCategoryId; ????private?List<User>?userList; ????private?List<Website>?websiteList; ???? ????public?Integer?getId()?{ ????????return?id; ????} ????public?Category()?{ ????????super(); ????} ????public?void?setId(Integer?id)?{ ????????this.id?=?id; ????} ????public?String?getName()?{ ????????return?name; ????} ????public?void?setName(String?name)?{ ????????this.name?=?name?==?null???null?:?name.trim(); ????} ????public?Integer?getParentCategoryId()?{ ????????return?parentCategoryId; ????} ????public?void?setParentCategoryId(Integer?parentCategoryId)?{ ????????this.parentCategoryId?=?parentCategoryId; ????} ????public?List<User>?getUserList()?{ ????????return?userList; ????} ????public?void?setUserList(List<User>?userList)?{ ????????this.userList?=?userList; ????} ????public?List<Website>?getWebsiteList()?{ ????????return?websiteList; ????} ????public?void?setWebsiteList(List<Website>?websiteList)?{ ????????this.websiteList?=?websiteList; ????} }中間類public?class?WebsiteToCategory?{ ????private?Integer?websiteId; ????private?Integer?categoryId; ????public?WebsiteToCategory()?{ ????????super(); ????} ???? ????public?Integer?getWebsiteId()?{ ????????return?websiteId; ????} ????public?void?setWebsiteId(Integer?websiteId)?{ ????????this.websiteId?=?websiteId; ????} ????public?Integer?getCategoryId()?{ ????????return?categoryId; ????} ????public?void?setCategoryId(Integer?categoryId)?{ ????????this.categoryId?=?categoryId; ????} }websitemapper:?<resultMap?id="BaseResultMap"?type="com.wechat.bean.score.Website"> ??????<id?column="id"?jdbcType="INTEGER"?property="id"/> ??????<result?column="name"?jdbcType="VARCHAR"?property="name"/> ??????<result?column="website_address"?jdbcType="VARCHAR"?property="websiteAddress"/> ??????<collection?property="categoryList"?column="{website_id=id}" ??????????????????select="com.wechat.dao.WebsiteToCategoryMapper.selectCategoryByWebsiteId"/> ??</resultMap> ??<select?id="selectByPrimaryKey"?parameterType="java.lang.Integer"?resultMap="BaseResultMap"> ??select?* ??from?website ??where?id?=?#{id,jdbcType=INTEGER} </select>categorymapper:<resultMap?id="BaseResultMap"?type="com.wechat.bean.score.Category"> ????<id?column="id"?jdbcType="INTEGER"?property="id"?/> ????<result?column="name"?jdbcType="VARCHAR"?property="name"?/> ????<result?column="parent_category_id"?jdbcType="INTEGER"?property="parentCategoryId"?/> ????<collection?property="websiteList"?ofType="com.wechat.bean.score.Website"?column="category_id"?select="com.wechat.dao.WebsiteToCategoryMapper.selectWebsiteByCategoryId"?/> ??</resultMap> ??<select?id="selectByPrimaryKey"?parameterType="java.lang.Integer"?resultMap="BaseResultMap"> ????select?* ????from?category ????where?id?=?#{id,jdbcType=INTEGER} ??</select> </mapper>中間類mapper:<!--根據網站id查分類--> <resultMap?id="BaseResultMap1"?type="com.wechat.bean.score.Category"> ??<id?column="id"?jdbcType="INTEGER"?property="id"?/> ??<result?column="name"?jdbcType="VARCHAR"?property="name"?/> ??<result?column="parent_category_id"?jdbcType="INTEGER"?property="parentCategoryId"?/> </resultMap> <select?id="selectCategoryByWebsiteId"?parameterType="Integer"?resultMap="BaseResultMap1"> ??SELECT?c.*?FROM?category?c,website_to_category?wc?WHERE?c.id=wc.category_id?and?wc.website_id=#{website_id} </select> <!--根據分類id查網站--> <resultMap?id="BaseResultMap2"?type="com.wechat.bean.score.Website"> ??<id?column="id"?jdbcType="INTEGER"?property="id"/> ??<result?column="name"?jdbcType="VARCHAR"?property="name"?/> ??<result?column="website_address"?jdbcType="VARCHAR"?property="websiteAddress"?/> </resultMap> <select?id="selectWebsiteByCategoryId"?parameterType="Integer"?resultMap="BaseResultMap2"> ??SELECT?w.*?FROM?website?w,website_to_category?wc?WHERE?w.id=wc.website_id?and?wc.category_id=#{category_id} </select>直接執行中間類的兩個方法是都可以查詢出來的,但放在collection中子查詢就不行開始我在websitemapper中的resultmap中的collenction的column寫的市sebsite_id,查詢出來的對象list是空的又改成column="{website_id=id}"想讓他強制執行,結果就一直報錯Error instantiating class java.lang.Integer with invalid types () or values (). Cause: java.lang.NoSuchMethodException: java.lang.Integer.<init>()
查看完整描述

3 回答

?
精慕門9254224

TA貢獻167條經驗 獲得超46個贊

parameterType 要寫成java.lang.Integer

查看完整回答
反對 回復 2017-09-02
  • 3 回答
  • 0 關注
  • 7108 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號