Mybatis--动态sql之choose、when、otherwise语句(只匹配其中的一个条件)
发布日期:2021-05-06 22:26:01 浏览次数:23 分类:技术文章

本文共 1005 字,大约阅读时间需要 3 分钟。

1. Mybatis–动态sql之choose、when、otherwise语句

有时候,我们不想使用所有的条件,而只是想从多个条件中选择一个使用。针对这种情况,MyBatis 提供了 choose 元素,它有点像 Java 中的 switch 语句。


数据库表 mybatis.blog

在这里插入图片描述

1.1 Mapper接口

BlogMapper.java

List
queryBlogChoose(Map map);

1.2 Mapper.xml


1.3 测试

@org.junit.Test    public void test02() {
SqlSession sqlSession = MybatisUtils.getSqlSession(); BlogMapper mapper = sqlSession.getMapper(BlogMapper.class); Map map = new HashMap(); map.put("views", 9999);// map.put("author", "天天天");// map.put("title", "微服务"); List
blogs = mapper.queryBlogChoose(map); for (Blog blog : blogs) {
System.out.println(blog); } }

在这里插入图片描述



上一篇:坑啊,Spring的BeanUtils是这样用的,为啥会出bug?
下一篇:挑战10个最难回答的Java面试题(附答案)

发表评论

最新留言

很好
[***.229.124.182]2025年03月29日 02时23分42秒