Mapped Statements collection does not contain value for xxx问题解决方法

今天在一次查询中,发生了一个非法参数异常,提示

Mapped Statements collection does not contain value for cn.edu.sgu.www.mapper.CommentImageMapper.selectByCommentId

一般看到Mapped Statements collection does not contain value for xxx类似的提示就是找不到xxx对应的方法,检查方法是否存在、包名是否正确,这里的问题就是包名不正确导致的。

package cn.edu.sgu.www.fresheveryday.mapper;

import cn.edu.sgu.www.fresheveryday.pojo.entity.Comment;
import cn.edu.sgu.www.fresheveryday.pojo.vo.CommentVO;
import cn.edu.sgu.www.fresheveryday.pojo.vo.UserSimpleVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentMapper extends BaseMapper<Comment> {
    /**
     * 通过商品id查询评论
     * @param productId 商品id
     * @return List<CommentVO>
     */
    @Select("select id, content, type, user_id, comment_id, created from comment where product_id = #{productId}")
    @Result(column = "id", property = "id")
    @Result(column = "comment_id", property = "commentId")
    @Result(
            column = "id", property = "images",
            many = @Many(select = "cn.edu.sgu.www.mapper.CommentImageMapper.selectByCommentId")
    )
    @Result(
            column = "user_id", property = "user", javaType = UserSimpleVO.class,
            one = @One(select = "cn.edu.sgu.www.fresheveryday.mapper.UserMapper.selectSimpleUserById")
    )
    List<CommentVO> selectByProductId(int productId);
}

这里是因为少了一层fresheveryday包,修改之后的代码能正常运行

package cn.edu.sgu.www.fresheveryday.mapper;

import cn.edu.sgu.www.fresheveryday.pojo.entity.Comment;
import cn.edu.sgu.www.fresheveryday.pojo.vo.CommentVO;
import cn.edu.sgu.www.fresheveryday.pojo.vo.UserSimpleVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentMapper extends BaseMapper<Comment> {
    /**
     * 通过商品id查询评论
     * @param productId 商品id
     * @return List<CommentVO>
     */
    @Select("select id, content, type, user_id, comment_id, created from comment where product_id = #{productId}")
    @Result(column = "id", property = "id")
    @Result(column = "comment_id", property = "commentId")
    @Result(
            column = "id", property = "images",
            many = @Many(select = "cn.edu.sgu.www.fresheveryday.mapper.CommentImageMapper.selectByCommentId")
    )
    @Result(
            column = "user_id", property = "user", javaType = UserSimpleVO.class,
            one = @One(select = "cn.edu.sgu.www.fresheveryday.mapper.UserMapper.selectSimpleUserById")
    )
    List<CommentVO> selectByProductId(int productId);
}

好了,文章就分享到这里了,感谢阅读~

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值