<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: