为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 6923 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信