XML中WHERE条件参数的形式问题
来源:8-9 显示评论列表【文章评论】
慕勒3498910
2023-01-29
老师:你好。不知道,之前的同学在完成这边查询评论列表数据功能的时候,在XML这边WHERE条件的形式书写上,有没有遇到过我这边的问题,如果,我这边选择这样的给定条件的时候:
// com/imooc/article/service/impl/CommentPortalServiceImpl.java中的方法定义:
public PagedGridResult queryArticleComments(String articleId, Integer page, Integer pageSize) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("articleId", articleId);
PageHelper.startPage(page, pageSize);
List<CommentsVO> comments = commentsCustomMapper.queryArticleComments(paramMap);
return setterPagedGrid(comments, page);
}
// com/imooc/article/mapper/CommentsCustomMapper.java中的方法定义如下:
List<CommentsVO> queryArticleComments(@Param("paramMap") Map<String, Object> paramMap);
// mapper/CommentsCustomMapper.xml具体的SQL语句内容如下:
<select id="queryArticleComments"
resultType="com.imooc.pojo.vo.CommentsVO"
parameterType="Map">
SELECT c.id AS commentId,
c.father_id AS fatherId,
c.article_id AS articleId,
c.comment_user_id AS commentUserId,
c.comment_user_nickname AS commentUserNickname,
c.content,
c.create_time AS createTime,
f.comment_user_nickname AS quoteUserNickname,
f.content AS quoteContent
FROM comments AS c
LEFT JOIN comments AS f
ON c.father_id = f.id
WHERE c.article_id = #{paramMap.articleId}
ORDER BY c.create_time DESC
</select>也就是这句话:
WHERE c.article_id = #{paramMap.articleId}当这么使用的时候,最终,无法查询到应该有的评论测试列表数据,查询到的结果为空,不太对。但是,如果是这么用的话,
WHERE c.article_id = #{articleId} // 也就是没有paramMap.作为前缀也就是把"paramMap.",这段给去掉,最后,得到的评论列表数据,是符合预期的,和Navicat中得到的结果是一致的,应该这两种写法都是可以的,为什么我这边非得去掉"paramMap."才能正确拿到查询数据呢?是我忽略了什么问题么?
写回答
1回答
-
风间影月
2023-01-29
啥意思啊?没有明白,是语法有问题吗???
032023-01-29
相似问题