<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=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);
mybatis復雜實體類的封裝(這樣做可能會使pageHelper不能分頁)
mapper.xml直接把這個CategoryVo返回
第二種封裝復雜查詢的方法(可以解決pageHelper不能分頁的問題)
這個第二個sql: