Official website address:
http://www.mybatis.tk/
https://gitee.com/free
: 1. Use springboot, adding a dependency
not need to reference mybatis official native of after use mybatis tk.
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
2.yml added to scan mapper interfaces
mapper:
mappers:
- com.example.testmybatis.testmapper.mapper.StuDescMapper
notEmpty: true
3. Define your own mapper Mapper succession of tk
import com.example.testmybatis.testmapper.entity.StuDesc;
import tk.mybatis.mapper.common.Mapper;
@org.apache.ibatis.annotations.Mapper
public interface StuDescMapper extends Mapper<StuDesc> {
}
4. These may be used directly after doing the service layer operations based on a number of the single table.
Note:
Definition and corresponding entity table, highlight the keyword when mysql entity in our field, if we are a handwritten sql, sql only need to use the `` desc caused to the good, and now we are not write your own sql, using @Column (name = "field needs to be escaped"), as shown below
import tk.mybatis.mapper.annotation.KeySql;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = "s_desc")
public class StuDesc {
private String id;
@Id
@KeySql(useGeneratedKeys = true)
private Integer userId;
private String scoreLevel;
@Column(name = "`desc`")
private String desc;
Note: The
use of guidance
https://github.com/abel533/Mapper/wiki