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:<!--根據(jù)網(wǎng)站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>
<!--根據(jù)分類id查網(wǎng)站-->
<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>直接執(zhí)行中間類的兩個(gè)方法是都可以查詢出來(lái)的,但放在collection中子查詢就不行開(kāi)始我在websitemapper中的resultmap中的collenction的column寫的市sebsite_id,查詢出來(lái)的對(duì)象list是空的又改成column="{website_id=id}"想讓他強(qiáng)制執(zhí)行,結(jié)果就一直報(bào)錯(cuò)Error instantiating class java.lang.Integer with invalid types () or values (). Cause: java.lang.NoSuchMethodException: java.lang.Integer.<init>()
添加回答
舉報(bào)
0/150
提交
取消