tkmybatis基础使用+mybatis generator

为啥要用tkmybatis :

https://www.cnblogs.com/wz2cool/p/7286377.html

使用流程:

1. pom

      

 
            tk.mybatis
            mapper
            3.4.2
        


        
            tk.mybatis
            mapper-spring-boot-starter
            1.1.3
        

    
            org.mybatis.generator
            mybatis-generator-core
            1.3.7
        

2.Mapper

package com.zxy.test.security.mapper;

import com.zxy.test.security.entity.User;

import tk.mybatis.mapper.common.Mapper;

public interface UserMapper  extends Mapper{ //Mapper接口有很多封装过的方法,不再一定需要mapper.xml

}
 

3.entity

package com.zxy.test.security.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;

@Data
@Table(name = "tb_user")
public class User implements Serializable {

    private static final long serialVersionUID = 3497935890426858541L;
    
    @Id
    private int id;
    
    @Column(name = "user_name")
    private String userName;

    private String password;

    //判断账户是否未过期
    @Transient
    private boolean accountNonExpired = true;

    //判断账户是否未锁定
    @Column(name = "account_non_locked")
    private boolean accountNonLocked = true;

    //密码是否未过期
    @Column(name = "credentials_non_Expired")
    private boolean credentialsNonExpired = true;

    //判断用户是否可用
    private boolean enabled = true;
    }

over 然后直接调用 

tkmybatis基础使用+mybatis generator_第1张图片

mybatis genertor自动生成代码

 生成的文件有mapper接口 mapper.xml文件跟entity对象 

貌似跟上面不需要mapper.xml的tk mybatis不搭嘎 汗 写在一起节约时间吧

pom文件在上面有,然后是genertor xml的内容




 
       
       
       
       
       
           
       

       
           
           
       

 
       
                    connectionURL="jdbc:mysql://127.0.0.1:3306/securityTest" userId="root"
            password="123456" />
            
        
            
        

        
        
       
           
            
            
            
            
       

 
       
        
            
        

        
        
        
            
        

        
        
        

                enableCountByExample="false" 
                enableUpdateByExample="false" 
              enableDeleteByExample="false" 
              enableSelectByExample="false" 
              selectByExampleQueryId="false">
            
        

   

比较需要注意的地方是: targetProject:项目名+src/main/resources 生成到资源目录下,然后这边使用的工具是sts4 需要装插件 百度一下吧

tkmybatis基础使用+mybatis generator_第2张图片

 

......................................

插件装好之后 直接生成就行了

 

 

 

你可能感兴趣的:(spring_boot,tkmybatis)