Java Code Examples for net.dreamlu.mica.core.utils.BeanUtil#copyWithConvert()
The following examples show how to use
net.dreamlu.mica.core.utils.BeanUtil#copyWithConvert() .
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: BeanUtilTest.java From mica with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void test4() { User1 user1 = new User1(); user1.setId("1"); user1.setName("张三"); user1.setSix("男"); User userx = BeanUtil.copyWithConvert(user1, User.class); System.out.println(userx); User user = new User(); user.setXx("123123"); user.setPhoto("www.dreamlu.net/img/1"); BeanUtil.copy(user1, user); System.out.println(user); Assert.assertNull(user.getId()); Assert.assertEquals("张三", user.getName()); }
Example 2
Source File: UserCopy4Test.java From mica-example with Apache License 2.0 | 6 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. 使用 mica 的 BeanUtil copyWithConvert 方法 UserVo userVo = BeanUtil.copyWithConvert(user, UserVo.class); // 3. 打印结果:UserVo(name=如梦技术, age=30, birthday=19-4-30 下午10:04) System.out.println(userVo); }
Example 3
Source File: BeanUtilTest.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void test2() { Map<String, Object> map = new HashMap<>(); map.put("id", 1); map.put("name", "张三"); map.put("data", "1,2,3"); map.put("gender", "女"); User1 user = BeanUtil.copyWithConvert(map, User1.class); System.out.println(user); Assert.assertEquals(user.getId(), "1"); }
Example 4
Source File: BeanUtilTest.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void test3() { Map<String, String> map = new HashMap<>(); map.put("id", "1"); map.put("idInt", "123"); map.put("name", "张三"); map.put("data", "1,2,3"); map.put("gender", "男"); User1 user = BeanUtil.copyWithConvert(map, User1.class); System.out.println(user); Assert.assertEquals(user.getIdInt().intValue(), 123); }
Example 5
Source File: BeanUtilTest.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void test5() { List<User1> list = new ArrayList<>(); for (int i = 0; i < 10; i++) { User1 user1 = new User1(); user1.setId(i + ""); user1.setName("张三" + i); list.add(user1); } List<User> copy1 = BeanUtil.copy(list, User.class); copy1.forEach(System.out::println); List<User> copy2 = BeanUtil.copyWithConvert(list, User.class); copy2.forEach(System.out::println); }
Example 6
Source File: BeanUtilTest.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void test6() { User user = new User(); user.setXx("123123"); user.setPhoto("www.dreamlu.net/img/1"); user.setBirthday(LocalDateTime.now()); User1 user1 = BeanUtil.copyWithConvert(user, User1.class); System.out.println(user1); }
Example 7
Source File: MapToBeanTest.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
public static void main(String[] args) { // 设置 cglib 源码生成目录 String sourcePath = BeanCopyUtilTest.class.getResource("/").getPath().split("mica-core")[0]; System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, sourcePath + "gen_code"); Map<String, Object> map = new HashMap<>(); map.put("id", 1); map.put("name", "张三"); map.put("six", "女"); map.put("gender", "男"); map.put("xx", "xx"); map.put("xInt", 100); map.put("xxInt", 101); map.put("xLong", 10000L); User1 user1 = BeanUtil.copy(map, User1.class); System.out.println(user1); System.out.println(BeanUtil.toMap(user1)); User1 userx = new User1(); BeanUtil.copy(user1, userx); System.out.println(userx); User1 user2 = BeanUtil.copyWithConvert(map, User1.class); System.out.println(user2); User user3 = BeanUtil.copy(map, User.class); System.out.println(user3); User user4 = BeanUtil.copyWithConvert(map, User.class); System.out.println(user4); User user5 = BeanUtil.copy(user2, User.class); System.out.println(user5); }
Example 8
Source File: BeanUtilTest.java From mica with GNU Lesser General Public License v3.0 | 4 votes |
public static void main(String[] args) { // 设置 cglib 源码生成目录 String sourcePath = BeanUtilTest.class.getResource("/").getPath().split("mica-core")[0]; System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, sourcePath + "gen_code"); User1 user1 = new User1(); user1.setId("1"); user1.setId1(11); user1.setIds(new Integer[]{1, 2, 3}); user1.setIdss(new int[]{1, 2, 3, 4, 5, 6}); user1.setIdx(new long[]{1, 2, 3, 4, 5, 6}); user1.setName("张三"); BeanUtil.toMap(user1); User user = new User(); user.setXx("123123"); user.setPhoto("www.dreamlu.net/img/1"); BeanUtil.copy(user1, user); System.out.println(user); User userx = BeanUtil.copyWithConvert(user1, User.class); System.out.println(userx); User userxx = new User(); userxx.setXx("123123"); userxx.setPhoto("www.dreamlu.net/img/1"); BeanUtil.copyNonNull(user1, userxx); System.out.println(userxx); User userxxx = BeanUtil.copyWithConvert(user1, User.class); System.out.println(userxxx); UserChain userChain = BeanUtil.copy(user, UserChain.class); System.out.println(userChain); Map<String, Object> data = new HashMap<>(); data.put("id", 1); UserChain userChainx = BeanUtil.copy(data, UserChain.class); System.out.println(userChainx); Map<String, Object> data1 = new HashMap<>(); data1.put("id", 1); data1.put("name", 1); data1.put("photo", 1); data1.put("xx", 1); UserChain userChainx1 = BeanUtil.copyWithConvert(data1, UserChain.class); System.out.println(userChainx1); Map<String, Object> data2 = new HashMap<>(); data2.put("id", 1); data2.put("name", "1"); data2.put("photo", "1"); data2.put("xx", "1"); data2.put("a", new int[]{1, 2, 3}); data2.put("allowNull", null); UserChain userChainxxxx = BeanUtil.toBean(data2, UserChain.class); System.out.println(userChainxxxx); Map<String, Object> dataxxxx = BeanUtil.toMap(userChainxxxx); System.out.println(dataxxxx); UserChain userChainNull = new UserChain(); userChainNull.setAllowNull(10000); BeanUtil.copyNonNull(data2, userChainNull); System.out.println(userChainNull); UserChain userChainNonNull = new UserChain(); userChainNonNull.setAllowNull(10000); BeanUtil.copy(data2, userChainNonNull); System.out.println(userChainNonNull); }
Example 9
Source File: BeanCopyConvertBenchmark.java From mica-jmh with MIT License | 4 votes |
@Benchmark public ToConvertUser micaBeanCopy() { return BeanUtil.copyWithConvert(user, ToConvertUser.class); }