Search in sources :

Example 1 with StrUtil

use of cn.hutool.core.util.StrUtil in project hutool by looly.

the class BeanUtilTest method beanToBeanCopyOptionsTest.

/**
 * @author dazer
 *  copyProperties(Object source, Object target, CopyOptions copyOptions)
 *  当:copyOptions的 setFieldNameEditor 不为空的时候,有bug,这里进行修复;
 */
@Test
public void beanToBeanCopyOptionsTest() {
    ChildVo1 childVo1 = new ChildVo1();
    childVo1.setChild_address("中国北京五道口");
    childVo1.setChild_name("张三");
    childVo1.setChild_father_name("张无忌");
    childVo1.setChild_mother_name("赵敏敏");
    CopyOptions copyOptions = CopyOptions.create().setFieldNameEditor(StrUtil::toUnderlineCase);
    ChildVo2 childVo2 = new ChildVo2();
    BeanUtil.copyProperties(childVo1, childVo2, copyOptions);
    Assert.assertEquals(childVo1.getChild_address(), childVo2.getChildAddress());
    Assert.assertEquals(childVo1.getChild_name(), childVo2.getChildName());
    Assert.assertEquals(childVo1.getChild_father_name(), childVo2.getChildFatherName());
    Assert.assertEquals(childVo1.getChild_mother_name(), childVo2.getChildMotherName());
}
Also used : StrUtil(cn.hutool.core.util.StrUtil) CopyOptions(cn.hutool.core.bean.copier.CopyOptions) Test(org.junit.Test)

Example 2 with StrUtil

use of cn.hutool.core.util.StrUtil in project hutool by looly.

the class AnsiSqlDialect method psForInsertBatch.

@Override
public PreparedStatement psForInsertBatch(Connection conn, Entity... entities) throws SQLException {
    if (ArrayUtil.isEmpty(entities)) {
        throw new DbRuntimeException("Entities for batch insert is empty !");
    }
    // 批量,根据第一行数据结构生成SQL占位符
    final SqlBuilder insert = SqlBuilder.create(wrapper).insert(entities[0], this.dialectName());
    final Set<String> fields = CollUtil.filter(entities[0].keySet(), StrUtil::isNotBlank);
    return StatementUtil.prepareStatementForBatch(conn, insert.build(), fields, entities);
}
Also used : StrUtil(cn.hutool.core.util.StrUtil) SqlBuilder(cn.hutool.db.sql.SqlBuilder) DbRuntimeException(cn.hutool.db.DbRuntimeException)

Aggregations

StrUtil (cn.hutool.core.util.StrUtil)2 CopyOptions (cn.hutool.core.bean.copier.CopyOptions)1 DbRuntimeException (cn.hutool.db.DbRuntimeException)1 SqlBuilder (cn.hutool.db.sql.SqlBuilder)1 Test (org.junit.Test)1