tkmybatis

作者: 蓝色_fea0 | 来源:发表于2018-11-07 14:58 被阅读231次

    1/配置

            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper-spring-boot-starter</artifactId>
                <version>2.0.4</version>
            </dependency>
    如果项目中已经使用了@MapperScan 就把它的包改成
    import tk.mybatis.spring.annotation.MapperScan;
    
    如果没有使用的话 可以直接在dao层使用@mapper
    

    2.1/初始化实体类

    import lombok.Data;
    
    import javax.persistence.Id;
    import javax.persistence.Table;
    import java.io.Serializable;
    
    @Data
    @Table(name = "student")
    public class Student implements Serializable {
    
        @Id
        private Long id;
    
        private String name;
    
        private Integer sex;
    }
    

    2.2/dao层与mapper.xml

    import com.huazhu.portal.entity.Student;
    import tk.mybatis.mapper.common.Mapper;
    import tk.mybatis.mapper.common.MySqlMapper;
    
    @org.apache.ibatis.annotations.Mapper
    public interface StudentMapper extends Mapper<Student> {
    
    }
    
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.huazhu.portal.dao.StudentMapper" >
    
    </mapper>
    

    官方文档

    相关文章

      网友评论

          本文标题:tkmybatis

          本文链接:https://www.haomeiwen.com/subject/pghvxqtx.html