fastmybatis 2.1.0 is released, the update content is as follows:
- Support for multi-tenancy
- Added ActiveRecord mode
multi-tenancy
fastmybatis supports two ways to achieve multi-tenancy: isolation by field and isolation by table name
For the specific implementation, please refer to the document: Multi-tenancy
ActiveRecord mode
The entity class implements the com.gitee.fastmybatis.core.support.Record
interface to have ActiveRecord mode
Entity class:
/**
* Active Record
* 表名:user_info
* 备注:用户信息表
*/
@Table(name = "user_info")
public class UserInfoRecord implements Record {
...
}
Test case:
// 保存全部字段
@Test
public void save() {
UserInfoRecord userInfoRecord = new UserInfoRecord();
userInfoRecord.setUserId(11);
userInfoRecord.setCity("杭州");
userInfoRecord.setAddress("西湖");
boolean success = userInfoRecord.save();
Assert.assertTrue(success);
}
// 保存不为null的字段
@Test
public void saveIgnoreNull() {
UserInfoRecord userInfoRecord = new UserInfoRecord();
userInfoRecord.setUserId(11);
userInfoRecord.setCity("杭州");
userInfoRecord.setAddress("西湖");
boolean success = userInfoRecord.saveIgnoreNull();
Assert.assertTrue(success);
}
// 修改全部字段
@Test
public void update() {
UserInfoRecord userInfoRecord = new UserInfoRecord();
userInfoRecord.setId(4);
userInfoRecord.setUserId(11);
userInfoRecord.setCity("杭州");
userInfoRecord.setAddress("西湖");
boolean success = userInfoRecord.update();
Assert.assertTrue(success);
}
// 修改不为null的字段
@Test
public void updateIgnoreNull() {
UserInfoRecord userInfoRecord = new UserInfoRecord();
userInfoRecord.setId(5);
userInfoRecord.setUserId(11);
userInfoRecord.setCity("杭州");
userInfoRecord.setAddress("西湖");
boolean success = userInfoRecord.updateIgnoreNull();
Assert.assertTrue(success);
}
// 保存或修改不为null的字段
@Test
public void saveOrUpdateIgnoreNull() {
UserInfoRecord userInfoRecord = new UserInfoRecord();
userInfoRecord.setUserId(11);
userInfoRecord.setCity("杭州");
userInfoRecord.setAddress("西湖");
boolean success = userInfoRecord.saveOrUpdateIgnoreNull();
Assert.assertTrue(success);
System.out.println("id:" + userInfoRecord.getId());
}
// 删除记录
@Test
public void delete() {
UserInfoRecord userInfoRecord = new UserInfoRecord();
userInfoRecord.setId(8);
boolean success = userInfoRecord.delete();
Assert.assertTrue(success);
}
About fastmybatis
fastmybatis is a mybatis development framework, its purpose is: simple, fast and effective.
- Quick start with zero configuration
- CRUD operations can be done without writing xml files
- 支持mysql、sqlserver、oracle、postgresql、sqlite
- Support custom sql, no need to write SQL for basic addition, deletion, modification and query, other special SQL (such as statistical SQL) can be written in xml
- Support integration with spring-boot, just rely on starter
- Support plug-in writing
- Support ActiveRecord mode
- Support for multi-tenancy
- Provide general service
- Lightweight, non-invasive, an extension of the official mybatis