今天在一次查询中,发生了一个非法参数异常,提示
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);
}
好了,文章就分享到这里了,感谢阅读~