Skip to content

GitHub-Laziji/commons-mybatis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

commons-mybatis

Mybatis通用数据层

通用Mapper, Dao, Service

适用于遵循阿里巴巴java开发规范的数据库表

  • 表必备字段: id, gmt_create, gmt_modified
  • id必为主键, 类型为unsigned bigint, 单表时自增, 步长为1
  • gmt_create, gmt_modified的类型均为date_time类型
  • 禁用保留字, 如descrangematchdelayed... 请参考MySQL官方保留字
  • 表名、字段名必须使用小写字母或数字, 禁止出现数字开头, 禁止两个下划线中间只出现数字

使用

简单编写实体类就可以使用了, 以下代码也可以使用代码生成器自动生成

https://github.com/GitHub-Laziji/mybatis-generator 模版选择mybatis2即可

引人

git clone https://github.com/GitHub-Laziji/commons-mybatis.git
cd commons-mybatis
mvn install
<dependency>
    <groupId>org.laziji.commons</groupId>
    <artifactId>commons-mybatis</artifactId>
    <version>2.0.0</version>
</dependency>

实体类

对于数据库user表

public class User extends BaseDO{
	private String username;
	private String password;
	//get set...
}

查询类

public class UserQuery extends BaseQuery<User> {

    private Long id;
    private Date gmtCreate;
    private Date gmtModified;
    private String username;
    private String usernameLike;
    private String password;
    private String passwordLike;
    //get set...
}

Dao、Service

Dao和Service直接继承通用的基类 不需要写内容, 也不需要编写XML

@Mapper
public interface UserDao extends DODao<User> {

}
@Service
public class UserService extends BaseDOService<User> {

}

直接使用

@RestController
public class UserController {

    @Autowired
    private DOService<User> userService;

    @RequestMapping("/")
    public void index(){
        //userService.select(query)
        //userService.selectById(id)
        //userService.selectAll()
        //userService.selectCount(query)
        //userService.selectTotal()
        //userService.selectPage(query)
        //userService.update(bean)
        //userService.insert(query)
        //userService.delete(id)
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages