假定Test实体表名为T_TEST, 含有id, type, name, value, desc字段:

主键更新:

Test test = new Test();

test.setType(1);

test.setId("uuid");

testService.update(test); // UPDATE T_TEST SET TYPE = 1 WHERE ID = 'uuid';

更新,列的值为空的更新NULL:

Test test = new Test();

test.setType(1);

test.setId("uuid");

// UPDATE T_TEST SET TYPE = 1, NAME = NULL,VALUE = NULL,DESC = NULL WHERE ID = 'uuid';

testService.update(test, true); 

更新,指定列的值为空的更新NULL:

Test test = new Test();

test.setType(1);

test.setId("uuid");

// UPDATE T_TEST SET TYPE = 1, NAME = NULL,VALUE = NULL WHERE ID = 'uuid';

testService.update(test, Test.T_NAME, Test.T_VALUE); 

按条件更新(也适合无主键更新或复核主键):

Test test = new Test();

test.setType(1);

// UPDATE T_TEST SET TYPE = 1 WHERE NAME = 'abc';

testService.updates(test, new Express(Test.T_NAME, "abc", ExpressionType.CDT_Equal)); 

按条件更新,列的值为空的更新NULL:

Test test = new Test();

test.setType(1);

// UPDATE T_TEST SET TYPE = 1, NAME = NULL,VALUE = NULL,DESC = NULL WHERE NAME = 'abc';

testService.updatesNull(test, new Express(Test.T_NAME, "abc", ExpressionType.CDT_Equal)); 

按条件更新,指定列的值为空的更新NULL:

Test test = new Test();

test.setType(1);

// UPDATE T_TEST SET TYPE = 1, VALUE = NULL WHERE NAME = 'abc';

testService.updatesNull(test, new String[]{Test.T_VALUE}, new Express(Test.T_NAME, "abc", ExpressionType.CDT_Equal)); 

 

目录
Copyright © objectsql.com 2021 闽ICP备17009107号-3

闽公网安备 35020302035600号