• springboot 整合tk.mapper


    
    
    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.0.0</version>
    </dependency>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <!--
    tkmybatis --> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>4.1.5</version> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.1.5</version> </dependency>
    mybatis:
      configuration:
        map-underscore-to-camel-case: true
      mapper-locations: classpath:mapper/*.xml
    mapper:
      identity: mysql
      not-empty: true

     

     Example example=new Example(Student.class);
            //创建criteria 
            Example.Criteria criteria = example.createCriteria();
            //条件为字段age在30-80岁的
            criteria.andBetween("age",30,80);
            Student stu=new Student();
            stu.setName("修改的");
            //这个stu是要修改的属性是哪些 example是修改的条件
            int i = studentMapper.updateByExample(stu, example);
    
            System.out.println(i);        
    example的用法
     Example example=new Example(Student.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("age","18");
     
            criteria.andLike("name","%张%");
            example.orderBy("age").desc();
            List<Student> students = studentMapper.selectByExample(example);
            students.forEach(System.out::println);   
    example的使用

    mybatis复杂实体类的封装(这样做可能会使pageHelper不能分页)

    mapper.xml直接把这个CategoryVo返回

     

     

    第二种封装复杂查询的方法(可以解决pageHelper不能分页的问题)

     

    这个第二个sql:

     

  • 相关阅读:
    Win10 蓝屏
    XE Button Color
    IOS 屏幕尺寸
    Delphi 转圈 原型进度条 AniIndicator 及线程配合使用
    Delphi 询问框 汉化
    Delphi Android 询问框
    Delphi BLE 控件
    浮点高低位赋值
    delphi 蓝牙 TBluetoothLE
    16进制字节转换
  • 原文地址:https://www.cnblogs.com/dkws/p/12102539.html
Copyright © 2020-2023  润新知