您现在的位置是:首页 >
当前栏目
hutool中@Alias
Alias hutool
2023-06-13 09:11:17 时间
我们可以使用hutool
中的@Alias
注解去给bean
取别名,例如:
@Data
public static class BeanWithAlias {
@Alias("name")
private String value1;
@Alias("age")
private Integer value2;
}
然后别名不仅能在BeanUtil.copyProperties
中使用,还可以在JSONUtil
中使用:
final BeanWithAlias beanWithAlias = new BeanWithAlias();
beanWithAlias.setValue1("张三");
beanWithAlias.setValue2(35);
final JSONObject jsonObject = JSONUtil.parseObj(beanWithAlias);
Assert.assertEquals("张三", jsonObject.getStr("name"));
Assert.assertEquals(new Integer(35), jsonObject.getInt("age"));
JSONObject json = JSONUtil.createObj()
.set("name", "张三")
.set("age", 35);
final BeanWithAlias bean = JSONUtil.toBean(Objects.requireNonNull(json).toString(), BeanWithAlias.class);
Assert.assertEquals("张三", bean.getValue1());
Assert.assertEquals(new Integer(35), bean.getValue2());
这个注解还是非常方便的
相关文章
- 这几个常用 alias,带你高效做事(下)
- axisfaultexception_this alias is not available
- ORA-22298: length of directory alias name or file name too long ORACLE 报错 故障修复 远程处理
- ORA-25437: duplicate table value for table alias: string ORACLE 报错 故障修复 远程处理
- ORA-25442: too many column values for table alias: string ORACLE 报错 故障修复 远程处理
- ORA-25469: data not specified for alias: string column name: string ORACLE 报错 故障修复 远程处理
- ORA-32046: sequence column name for SEARCH clause must not be part of the column alias list ORACLE 报错 故障修复 远程处理
- ORA-32039: recursive WITH clause must have column alias list ORACLE 报错 故障修复 远程处理
- ORA-32048: cycle mark column name for CYCLE clause must not be part of the column alias list ORACLE 报错 故障修复 远程处理
- linux:alias详解程序员
- Linux命令Alias:简化工作流程(linux命令alias)