美文网首页
mybatis中使用枚举判断

mybatis中使用枚举判断

作者: 若愚同学 | 来源:发表于2019-04-15 21:07 被阅读0次

需求:
1:联盟/部落玩家查询在线人数时只能查本阵营
2:管理员可以查询所有

枚举类
  • 此处我直接使用了lombok插件,如果不喜欢使用lombok插件的可以自己生成get方法和构造器
@Getter
@AllArgsConstructor
public enum UserType {

    GM("gm","游戏管理员"),
    ALLIANCE("alliance","联盟"),
    HORDE("horde","部落");

    private String code;
    private String name;
}
mapper.xml
<select id="countByType" resultType="int">
  select count(1) from `user`
  <where>
    <if test="code == 'alliance' or code == 'horde'">
      and `type` = #{type}
    </if>
  </where>
</select>
service.java/mapper.java
public interface IUserService {
    Integer countByType(UserType member);
}
public interface UserMapper {
    Integer countByType(UserType type);
}
service.java/mapper.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class UserServiceImplTest {

    @Autowired
    private IUserService userService;

    @Test
    public void count(){
        System.out.println(userService.countByType(UserType.ALLIANCE));
        System.out.println(userService.countByType(UserType.HORDE));
        System.out.println(userService.countByType(UserType.GM));
    }
}    

相关文章

  • mybatis判断使用枚举值

    其实有人说这样有点多余了, 明明可以直接把值写死啊,比如: 直接把值写成0就好了, 是的, 确实可以这样,但是这...

  • mybatis中使用枚举判断

    需求:1:联盟/部落玩家查询在线人数时只能查本阵营2:管理员可以查询所有 枚举类 此处我直接使用了lombok插件...

  • SpringBoot和mybatis项目中使用枚举

    枚举基类 枚举定义 mybatis类型处理器 mybatis.xml中配置 mybatis mapper文件中re...

  • mybaits if 标签中使用枚举判断

    mybaits if 标签中使用枚举判断 枚举定义 if标签中使用

  • Swift 基础笔记 - 枚举

    枚举 OC定义和使用枚举 Swift定义枚举类型 Swift判断枚举类型 枚举成员类型

  • Mybatis枚举使用

    枚举定义如下: 实体如下: 下面新增实体对象sex属性值为:SexEnum.nan,SQL中ID都自己设置,主要是...

  • MyBatis中使用枚举

    问题 在编码过程中,经常会遇到用某个数值来表示某种状态、类型或者阶段的情况,比如有这样一个枚举: 通常我们希望将表...

  • 2020-08-04

    mybatis-plus中判断list为空 使用list.size()>0判断 代码示例: idea快捷键 Ctr...

  • mybatis if标签判断字符串相等

    mybatis 映射文件中,if标签判断字符串相等,两种方式:因为mybatis映射文件,是使用的ognl表达式,...

  • mybatis if标签判断字符串相等

    mybatis 映射文件中,if标签判断字符串相等,两种方式: 因为mybatis映射文件,是使用的ognl表达式...

网友评论

      本文标题:mybatis中使用枚举判断

      本文链接:https://www.haomeiwen.com/subject/fckzvqtx.html