Mybatis-plus深入开发(详解insql和exists包含对应的not)

针对开源框架mybatis-plus的深入学习,在使用过程中针对insql和exsists(对应的not)进行简单的使用介绍:(前提是new QueryWrapper())

针对notInSql

notInSql(boolean condition, R column, String inValue); notInSql(R column, String inValue)

针对inSql

inSql(R column, String inValue) inSql(boolean condition, R column, String inValue)

eg:mapper.selectList(new QueryWrapper<XXX>().inSql(id, "select id from id where id = 2"));

针对exists

exists(String existsSql) exists(boolean condition, String existsSql)

针对notExists

notExists(String notExistsSql) notExists(boolean condition, String notExistsSql)

eg:QueryWrapper<xxxx> qw = new QueryWrapper<>(); qw.select("id","name").exists("select id from table where id= 2");

注:其中insql和exists中的sql语句可以动态拼接字符串就动态灵活了,eg: "select * from table where xxx in (" + value+")"类似这样的处理。

解决方案有问题,如果sql较为复杂建议使用xml直接操作,使用最开始的mybatis直接处理,(如where <if test=....></if> </where>等)


版权声明:本文为qq_25223941原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。