通用Mapper Spring Mvc

项目地址:https://github.com/mybatis/mybatis-3.git
1、使用
添加Maven依赖



    tk.mybatis
    mapper
    最新版本

TestExampleMapper

public interface TestExampleMapper extends Mapper {
}

实体类注解

public class TestExample {
    @Id
    private Integer id;
    @Column
    private String  name;
    private String logo;
    //省略setter和getter方法
}

简单用法示例

@Resource
private TestExampleMapper  mapper;

Condition condition = new Condition(TestExample .class);
condition .createCriteria().andGreaterThan("id", 100);
List exampleList = mapper.selectByCondition(condition );

spring 配置



      
      
      
      
      
      
      
      
          
              
                  
                      
                          dialect=mysql
                      
                  
              
          
      


 
        
        
            
                mappers=com.orm.Mapper
            
        
    

2、自定义

import tk.mybatis.mapper.common.BaseMapper;
import tk.mybatis.mapper.common.ConditionMapper;
import tk.mybatis.mapper.common.IdsMapper;
import tk.mybatis.mapper.common.special.InsertListMapper;

//定制接口
public interface Mapper
        extends
        BaseMapper,
        ConditionMapper,
        IdsMapper,
        InsertListMapper {
}

//引用
@Autowired
protected Mapper mapper;
//调用InsertListMapper的insertList方法
public void save(T model){
  mapper.insertList(models);
}

//tk的InsertListMapper接口源码
public interface InsertListMapper {
    @Options(
        useGeneratedKeys = true,
        keyProperty = "id"
    )
    @InsertProvider(
        type = SpecialProvider.class,
        method = "dynamicSQL"
    )
    int insertList(List var1);
}

你可能感兴趣的:(通用Mapper Spring Mvc)