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:

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM