Mybatis的升级版Mybatis-Plus的使用说明

(一).1.借鉴文章地址:http://dushen.iteye.com/blog/2406248?tdsourcetag=s_pcqq_aiomsg
2.在GitHub上对Mybatis-Plus用的较好的开源项目:https://github.com/baomidou/mybatis-plus

(二).Mybatis学习视频
http://www.icoolxue.com/album/show/216/

(三).如何集成spring与mybatisPlus.

  1. 导包
    导入mp的依赖时,就不需要再次导入mybatis与mybatis-spring的两个依赖;

  2. 配置相关的xml 文件;
    3.MybatisPlus的操作就是一个实体类的Mapper接口继承BaseMapper
    泛型T就是当前实体类对象;
    3.1.针对单表进行通用的CRUD操作时,是不需要再进行编写映射文件,因为BaseMapper已经编写了通用的方法;
    3.2.实体类Employee <---->数据库表 tbl_employee
    属性名: 字段名:
    Integer id <-----------> int id
    String lastName <----------->varchar last_name
    String email <---------------->varachar email
    Integer gender <------------> char gender
    Integer age <-----------> int age
    3.3.遇到的一些问题:
    3.3.1.比如进行插入操作时,实体类名与数据库表名不一致,需要加入注解
    @TableName(value=“tbl_employee”)
    public class Employee{}

     3.3.2.@TableId
     mybatisPlus主键生成策略,
     @TableName(value="tbl_employee")
       public class Employee{
                  @TableId(type="IdType.AUTO")
                  private Integer id;
    

}
3.3.3.mybatisPlus提供了全局策略配置,且要将此放入spring容器中(sqlSessionFactoryBean),才能生效

        <bean id="" class="GrobalConfiguration"></bean>
        在该全局策略配置中,可统一定义主键生成策略,表名对应,字段名对应问题(驼峰命名)

3.3.4.@TableField(value=“last_name”)
private String lastName;
可以指定属性名与表中字段名,也可以指定当该实体类中有一些属性不存在与表中时,
@TableField(exist=false)
private Double salary;

猜你喜欢

转载自blog.csdn.net/Elliot_Ji/article/details/83413504