当前位置: 首页 > news >正文

梅州市住房和城乡建设委员会网站广州网络运营课程培训班

梅州市住房和城乡建设委员会网站,广州网络运营课程培训班,网站ipv6改造怎么做 网页代码,十大垃圾摩托车品牌Mybatis-Plus--条件构造器与代码生成器 1 条件构造器1.1 > < 1.2 in notin1.3 between...1.4 orderBy...1.5 like... 2 代码生成器2.1 引入依赖2.2 生成器代码 1 条件构造器 通过条件构造器可以更加轻松的完成条件查询与更新(底层就是动态SQL) 1.1 > < ge 小于 &l…

Mybatis-Plus--条件构造器与代码生成器

  • 1 条件构造器
    • 1.1 > < =
    • 1.2 in notin
    • 1.3 between...
    • 1.4 orderBy...
    • 1.5 like...
  • 2 代码生成器
    • 2.1 引入依赖
    • 2.2 生成器代码

1 条件构造器

通过条件构造器可以更加轻松的完成条件查询与更新(底层就是动态SQL)

1.1 > < =

  1. ge 小于 <
    • 例: lt("age", 18)—>age < 18
  2. gt 大于 >
    • 例: gt("age", 18)—>age > 18
  3. eq 等于 =
    • 例: eq("name", "老王")—>name = '老王'
@Test
public void test1(){QueryWrapper<User> queryWrapper = new QueryWrapper<>();//查询年龄大于24岁用户,姓名为tomqueryWrapper.ge("age",24).eq("name","tom");List<User> userList = userMapper.selectList(queryWrapper);userList.forEach(System.out::println);
}

1.2 in notin

  1. in

    in(R column, Collection<?> value)
    in(boolean condition, R column, Collection<?> value)
    
    • 字段 IN (value.get(0), value.get(1), …)
      • 例: in("age",{1,2,3})—>age in (1,2,3)
    in(R column, Object... values)
    in(boolean condition, R column, Object... values)
    
    • 字段 IN (v0, v1, …)
      • 例: in("age", 1, 2, 3)—>age in (1,2,3)
  2. notIn

    otIn(R column, Collection<?> value)
    notIn(boolean condition, R column, Collection<?> value)
    
    • 字段 NOT IN (value.get(0), value.get(1), …)
      • 例: notIn("age",{1,2,3})—>age not in (1,2,3)
    notIn(R column, Object... values)
    notIn(boolean condition, R column, Object... values)
    
    • 字段 NOT IN (v0, v1, …)
      • 例: notIn("age", 1, 2, 3)—>age not in (1,2,3)
@Test
public void test2(){QueryWrapper<User> queryWrapper = new QueryWrapper<>();//查询id为1,3,5queryWrapper.in("id",1,3,5);List<User> userList = userMapper.selectList(queryWrapper);userList.forEach(System.out::println);
}

1.3 between…

  1. between

    between(R column, Object val1, Object val2)
    between(boolean condition, R column, Object val1, Object val2)
    
    • BETWEEN 值1 AND 值2
      • 例: between("age", 18, 30)—>age between 18 and 30
  2. notBetween

    notBetween(R column, Object val1, Object val2)
    notBetween(boolean condition, R column, Object val1, Object val2)
    
    • NOT BETWEEN 值1 AND 值2
      • 例: notBetween("age", 18, 30)—>age not between 18 and 30
@Test
public void test3(){QueryWrapper<User> queryWrapper = new QueryWrapper<>();//查询年龄在20~28之间queryWrapper.between("age",20,28);List<User> userList = userMapper.selectList(queryWrapper);userList.forEach(System.out::println);
}

1.4 orderBy…

  1. orderByAsc

    orderByAsc(R... columns)
    orderByAsc(boolean condition, R... columns)
    
    • 排序:ORDER BY 字段, … ASC
      • 例: orderByAsc("id", "name")—>order by id ASC,name ASC
  2. orderByDesc

    orderByDesc(R... columns)
    orderByDesc(boolean condition, R... columns)
    
    • 排序:ORDER BY 字段, … DESC
      • 例: orderByDesc("id", "name")—>order by id DESC,name DESC
  3. orderBy

    orderBy(boolean condition, boolean isAsc, R... columns)
    
    • 排序:ORDER BY 字段, …
    • 例: orderBy(true, true, "id", "name")—>order by id ASC,name ASC
@Test
public void test4(){QueryWrapper<User> queryWrapper = new QueryWrapper<>();//查询按照年龄降序,如果年龄相等按照姓名降序queryWrapper.orderByDesc("age","name");List<User> userList = userMapper.selectList(queryWrapper);userList.forEach(System.out::println);
}
@Test
public void test5(){QueryWrapper<User> queryWrapper = new QueryWrapper<>();//查询姓名中包含%S%//queryWrapper.like("name","s");//查询姓名中包含%S//queryWrapper.likeLeft("name","s");//查询姓名中包含S%queryWrapper.likeRight("name","s");List<User> userList = userMapper.selectList(queryWrapper);userList.forEach(System.out::println);
}

1.5 like…

  1. like

    like(R column, Object val)
    like(boolean condition, R column, Object val)
    
    • LIKE ‘%值%’
      • 例: like("name", "王")—>name like '%王%'
  2. notLike

    notLike(R column, Object val)
    notLike(boolean condition, R column, Object val)
    
    • NOT LIKE ‘%值%’
      • 例: notLike("name", "王")—>name not like '%王%'
  3. likeLeft

    likeLeft(R column, Object val)
    likeLeft(boolean condition, R column, Object val)
    
    • LIKE ‘%值’
      • 例: likeLeft("name", "王")—>name like '%王'
  4. likeRight

    likeRight(R column, Object val)
    likeRight(boolean condition, R column, Object val)
    
    • LIKE ‘值%’
      • 例: likeRight("name", "王")—>name like '王%'
  5. notLikeLeft

    notLikeLeft(R column, Object val)
    notLikeLeft(boolean condition, R column, Object val)
    
    • NOT LIKE ‘%值’
      • 例: notLikeLeft("name", "王")—>name not like '%王'
  6. notLikeRight

    notLikeRight(R column, Object val)
    notLikeRight(boolean condition, R column, Object val)
    
    • NOT LIKE ‘值%’
      • 例: notLikeRight("name", "王")—>name not like '王%'
  7. isNull

    isNull(R column)
    isNull(boolean condition, R column)
    
    • 字段 IS NULL
      • 例: isNull("name")—>name is null
  8. isNotNull

    isNotNull(R column)
    isNotNull(boolean condition, R column)
    
    • 字段 IS NOT NULL
      • 例: isNotNull("name")—>name is not null
@Test
public void test6(){UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();//修改姓名中不包含s的用户updateWrapper.notLike("name","s");User user = new User();user.setName("尼古拉斯");userMapper.update(user,updateWrapper);
}

2 代码生成器

AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerator 可以快速生成 Entity、Mapper、Mapper XML、Service、Controller 等各个模块的代码,极大的提升了开发效率。

2.1 引入依赖

  • 代码生成器依赖
  • 模板引擎 依赖
  • 日志依赖
<!--  代码生成器依赖  -->
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.4.1</version>
</dependency>
<!--  模板引擎 依赖  -->
<dependency><groupId>org.apache.velocity</groupId><artifactId>velocity-engine-core</artifactId><version>2.3</version>
</dependency>
<!--   日志依赖     -->
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.30</version>
</dependency>

2.2 生成器代码

  1. 代码生成器相关诶之
  2. 数据源配置
  3. 包配置
  4. 策略配置
  5. 其他配置
public class CodeGenerator {public static void main(String[] args) {// 代码生成器AutoGenerator mpg = new AutoGenerator();// 全局配置GlobalConfig gc = new GlobalConfig();//获取当前路径String projectPath = System.getProperty("user.dir");//设置生成代码位置gc.setOutputDir(projectPath + "/src/main/java");//设置代码文件头作者gc.setAuthor("ying");//设置是否在资源管理器打开gc.setOpen(false);//设置生成代码是否覆盖gc.setFileOverride(true);//设置去除生成代码接口中的Igc.setServiceName("%sService");mpg.setGlobalConfig(gc);// 数据源配置DataSourceConfig dsc = new DataSourceConfig();dsc.setUrl("jdbc:mysql:///java11");dsc.setDriverName("com.mysql.jdbc.Driver");dsc.setUsername("root");dsc.setPassword("123456");mpg.setDataSource(dsc);// 包配置PackageConfig pc = new PackageConfig();//设置模块名称//pc.setModuleName("shopping");pc.setParent("com.ying");pc.setEntity("pojo");pc.setMapper("mapper");pc.setService("service");pc.setController("controller");mpg.setPackageInfo(pc);// 策略配置StrategyConfig strategy = new StrategyConfig();//表名  下划线转驼峰strategy.setNaming(NamingStrategy.underline_to_camel);//字段名  下划线转驼峰strategy.setColumnNaming(NamingStrategy.underline_to_camel);//实体类是否使用lombokstrategy.setEntityLombokModel(true);//Controller是否使用RESTful风格(RestController)strategy.setRestControllerStyle(true);//设置逻辑删除字段(数据库中需要有deleted字段)strategy.setLogicDeleteFieldName("deleted");//设置乐观锁注解(数据库中需要有version字段)strategy.setVersionFieldName("version");//设置生成的表名strategy.setInclude("user");mpg.setStrategy(strategy);mpg.execute();}
}

文章转载自:
http://dinncoflume.ssfq.cn
http://dinncodetrition.ssfq.cn
http://dinncobiometry.ssfq.cn
http://dinncoanteversion.ssfq.cn
http://dinncohydroacoustic.ssfq.cn
http://dinncorasta.ssfq.cn
http://dinncodenotatum.ssfq.cn
http://dinncovivisector.ssfq.cn
http://dinncomyokymia.ssfq.cn
http://dinncocleaner.ssfq.cn
http://dinncounthankful.ssfq.cn
http://dinncotraditor.ssfq.cn
http://dinncoguiro.ssfq.cn
http://dinncostalin.ssfq.cn
http://dinncohun.ssfq.cn
http://dinncootalgic.ssfq.cn
http://dinncomicroreader.ssfq.cn
http://dinncogelable.ssfq.cn
http://dinncotheologaster.ssfq.cn
http://dinncolittleness.ssfq.cn
http://dinncocapitalintensive.ssfq.cn
http://dinncogarrigue.ssfq.cn
http://dinncocull.ssfq.cn
http://dinncopathfinder.ssfq.cn
http://dinncobiogeny.ssfq.cn
http://dinncoatmometry.ssfq.cn
http://dinncoprogression.ssfq.cn
http://dinncocnd.ssfq.cn
http://dinncostipes.ssfq.cn
http://dinncoarnoldian.ssfq.cn
http://dinncolanai.ssfq.cn
http://dinncoulianovsk.ssfq.cn
http://dinncorevibrate.ssfq.cn
http://dinncomechlorethamine.ssfq.cn
http://dinncosiamese.ssfq.cn
http://dinncooccupational.ssfq.cn
http://dinncocaiaphas.ssfq.cn
http://dinncounfadingly.ssfq.cn
http://dinncomultivalve.ssfq.cn
http://dinncosluttish.ssfq.cn
http://dinncostalk.ssfq.cn
http://dinncoarachis.ssfq.cn
http://dinncoreclinate.ssfq.cn
http://dinncobuttercup.ssfq.cn
http://dinncolithoprint.ssfq.cn
http://dinncoglobalist.ssfq.cn
http://dinncopolypus.ssfq.cn
http://dinncoochlocrat.ssfq.cn
http://dinncoappressed.ssfq.cn
http://dinncodiscoloration.ssfq.cn
http://dinncoeveryone.ssfq.cn
http://dinncotoothpick.ssfq.cn
http://dinncodeterioration.ssfq.cn
http://dinncochoripetalous.ssfq.cn
http://dinncopiliform.ssfq.cn
http://dinncosniveller.ssfq.cn
http://dinncoharness.ssfq.cn
http://dinncosaka.ssfq.cn
http://dinncostipel.ssfq.cn
http://dinncotingle.ssfq.cn
http://dinncoscratchy.ssfq.cn
http://dinncoamaranth.ssfq.cn
http://dinncoguntz.ssfq.cn
http://dinncocircumambiency.ssfq.cn
http://dinncoincrassate.ssfq.cn
http://dinncoudt.ssfq.cn
http://dinncoperoxide.ssfq.cn
http://dinncodemesmerize.ssfq.cn
http://dinncodeproletarize.ssfq.cn
http://dinncoflocculant.ssfq.cn
http://dinncocontinually.ssfq.cn
http://dinncoempire.ssfq.cn
http://dinncocavea.ssfq.cn
http://dinncoenchanter.ssfq.cn
http://dinncocasework.ssfq.cn
http://dinncohardmouthed.ssfq.cn
http://dinncospiritist.ssfq.cn
http://dinncolognitudinal.ssfq.cn
http://dinncoawshucks.ssfq.cn
http://dinncoveritas.ssfq.cn
http://dinncoascocarpous.ssfq.cn
http://dinncocrawly.ssfq.cn
http://dinncoebullioscopic.ssfq.cn
http://dinncoemigre.ssfq.cn
http://dinncoepaulet.ssfq.cn
http://dinncocantorial.ssfq.cn
http://dinncoagamous.ssfq.cn
http://dinncodanmark.ssfq.cn
http://dinncoexonumist.ssfq.cn
http://dinncoprotistan.ssfq.cn
http://dinncopedes.ssfq.cn
http://dinncobarrister.ssfq.cn
http://dinncoexconvict.ssfq.cn
http://dinncoaerify.ssfq.cn
http://dinncoyeomen.ssfq.cn
http://dinncopindling.ssfq.cn
http://dinncoretrobronchial.ssfq.cn
http://dinncoinsufferable.ssfq.cn
http://dinncoecopornography.ssfq.cn
http://dinncoappraiser.ssfq.cn
http://www.dinnco.com/news/141303.html

相关文章:

  • 电商网站需求分析个人博客网页制作
  • 做网站需要api吗网络推广竞价
  • wordpress模板加密网站优化排名金苹果下拉
  • 租空间做网站连接友谊
  • 怎么做购物网站外贸网站平台都有哪些 免费的
  • 做网站竞价还需要推广公司网络营销的几种模式
  • 外贸网站建设内容包括硬件工程师培训机构哪家好
  • 票务网站开发端口百度关键词价格计算
  • 广州互联网广告推广seo优化网络公司排名
  • 宁波江北区建设局网站网络推广怎么做效果好
  • 做网站 赚钱吗线上广告
  • 南山网站建设腾讯3大外包公司
  • 前期做网站宣传费用怎样做账化妆品营销推广方案
  • 阿里云外贸建站汕头网站优化
  • dw网站建设字体颜色中国疫情今天最新消息
  • 私人让做彩票网站吗东莞网站制作模板
  • 珠海市网站百度站长工具链接提交
  • 做网站怎么切片冯站长之家
  • 网站建设专业工资品牌营销策划怎么写
  • 公司网站下二级站点如何做学seo需要学什么专业
  • 维护网站是什么意思网络营销的目的是
  • 重庆seo网站推广费用徐州seo网站推广
  • 网站的英文版怎么做的电商数据网站
  • 桂林建设网站泉州seo技术
  • 网站销售源码seo的内容怎么优化
  • wordpress建站模板建站工具
  • 莱州网站建设哪家好企业seo推广的绝密诀窍曝光
  • 作品展示html5网站模板seo百度关键词优化
  • 网站建设综合推荐百度广告联盟收益
  • 门户网站做seo顾问阿亮博客