mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add ConditionBuilder
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConditionBuilderTest {
|
||||
|
||||
@Test
|
||||
public void buildTest(){
|
||||
Condition c1 = new Condition("user", null);
|
||||
Condition c2 = new Condition("name", "!= null");
|
||||
c2.setLinkOperator(LogicalOperator.OR);
|
||||
Condition c3 = new Condition("group", "like %aaa");
|
||||
|
||||
final ConditionBuilder builder = ConditionBuilder.of(c1, c2, c3);
|
||||
final String sql = builder.build();
|
||||
Assert.assertEquals("user IS NULL OR name IS NOT NULL AND group LIKE ?", sql);
|
||||
Assert.assertEquals(1, builder.getParamValues().size());
|
||||
Assert.assertEquals("%aaa", builder.getParamValues().get(0));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user