tkmybatis update
时间: 2023-11-18 10:03:23 浏览: 42
TkMybatis的update方法提供了多种方式来更新数据库记录。其中,常用的几种update方法包括:
1. `updateByPrimaryKey`: 根据主键更新所有属性。示例代码:
```
Test record = new Test();
record.setId(123);
record.setName("hello");
mapper.updateByPrimaryKey(record);
```
2. `updateByPrimaryKeySelective`: 根据主键更新有值属性。示例代码:
```
Test record = new Test();
record.setId(123);
record.setName("hello");
mapper.updateByPrimaryKeySelective(record);
```
3. `updateByExampleSelective`: 根据给定的example更新有值属性。示例代码:
```
Example example = new Example(Test.class);
example.createCriteria().andEqualTo("name", "test");
Test record = new Test();
record.setName("hello");
mapper.updateByExampleSelective(record, example);
```
这些方法都会生成对应的SQL语句来更新数据库记录。具体的SQL语句会根据实体类的属性以及条件进行动态生成。