当前位置: 代码网 > it编程>编程语言>Java > tk mybatis update各种类型使用及说明

tk mybatis update各种类型使用及说明

2026年04月24日 Java 我要评论
1.updatebyexample根据给定的example更新所有属性,包括主键id,所有属性都需要有值package com.bsx.test;public class test { priv

1.updatebyexample

根据给定的example更新所有属性,包括主键id,所有属性都需要有值

package com.bsx.test;
public class test {
    private int id;
    private string name;
    public int getid() {
        return id;
    }
    public void setid(int id) {
        this.id = id;
    }
    public string getname() {
        return name;
    }
    public void setname(string name) {
        this.name = name;
    }
}
example example = new example(test.class);
example.createcriteria().andequalto("name", "test");
test record = new test();
record.setname("hello");
mapper.updatebyexample(record, example);

解析后sql:

update o2o_video_file  set id = ?,name = ? where (  name = ? )

2.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:

update o2o_video_file  set name = ? where (  name = ? )

3.updatebyprimarykey

根据主键更新所有属性

test record = new test();
record.setid(123);
record.setname("hello");
mapper.updatebyprimarykey(record, example);

解析后sql:

update o2o_video_file  set id=?, name = ? where (  id = ? )

4.updatebyprimarykeyselective

根据主键更新有值属性

test record = new test();
record.setid(123);
record.setname("hello");
mapper.updatebyprimarykey(record, example);

解析后sql:

update o2o_video_file  set name = ? where (  id = ? )

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com