org.springframework.cglib.core.Converter Java Examples
The following examples show how to use
org.springframework.cglib.core.Converter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanTest.java From mica with GNU Lesser General Public License v3.0 | 6 votes |
public static void test2() { BeanCopier beanCopier = BeanCopier.create(User.class, UserVO.class, true); User user = new User(); user.setId(1); user.setName("如梦技术"); user.setAge(18); UserVO userVO = new UserVO(); // 此处 Converter 可使用 lambda 简化。 beanCopier.copy(user, userVO, new Converter() { @Override public Object convert(Object o, Class aClass, Object o1) { return null; } }); System.out.println(userVO); }
Example #2
Source File: UserCopy2Test.java From mica-example with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // 设置 cglib 源码生成目录 String sourcePath = "/Users/lcm/git/mica/mica-example/web-example/src/test/java"; System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, sourcePath); // 1. 初始化 user,赋值 User user = new User(); user.setId(250); user.setName("如梦技术"); user.setAge(30); user.setBirthday(LocalDateTime.now()); // 2. 初始化 userVo UserVo userVo = new UserVo(); // 3. 构造 BeanCopier,不是用类型转换 BeanCopier copier = BeanCopier.create(User.class, UserVo.class, true); // 4. 拷贝对象,不是用类型转换,转换器可以使用 null copier.copy(user, userVo, new Converter() { @Override public Object convert(Object o, Class aClass, Object o1) { if (o == null) { return null; } return ConvertUtil.convert(o, aClass); } }); // 5. 打印结果:UserVo(name=如梦技术, age=30, birthday=19-4-30 下午9:45) System.out.println(userVo); }