Map和Bean的相互转换】的更多相关文章

Map和Bean的相互转换 BeanUtils位于org.apache.commons.beanutils.BeanUtils下面,其方法populate的作用解释如下: 完整方法: BeanUtils.populate( Object bean, Map properties ), 这个方法会遍历map<key, value>中的key,如果bean中有这个属性,就把这个key对应的value值赋给bean的属性. 1.bean 转换成 map  Person person1=new Per…
1.背景 今天要做一个demo,从github上clone一个springmvc mybatis的工程(https://github.com/komamitsu/Spring-MVC-sample-using-iBatis) 打包成war后启动报错: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.…
本文使用json-lib jar包实现Json与bean的相互转换 1.将字符串转为JSON 使用JSONObject.fromObject(str)方法即可将字符串转为JSON对象 使用JSONObject.put("attribute","value")可为JSON添加属性 如果需要转为JSON数组,只需使用JSONArray对象提供的方法即可 /** * 一些简单的转换 */ public static void transformStringTest() {…
1.使用jar包生成xsd文件 java -jar trang.jar a.xml a.xsd xml格式 生成的xsd文件 2.使用xjc命令生成bean文件 xjc a.xsd 生成的相关bean文件 3.xml与bean的相互转换 xml转bean Codes codes = JAXB.unmarshal(new FileReader("test.xml"), Codes.class); bean转xml JAXB.marshal(codes, new FileOutputStr…
[转 :http://www.fanfanyu.cn/news/staticpagefile/2351.html] 最近在开发项目的过程中SpringMVC抛了个"Ambiguous mapping found. Cannot map 'clientPoolController' bean method"异常出来,如下(只列出重要的部分,以免篇幅过长): org.springframework.beans.factory.BeanCreationException: Error cre…
原文:https://blog.csdn.net/justry_deng/article/details/90758250 相关说明:在SpringBoot中,我们可以通过以下几种方式获取并绑定配置文件中的信息: @Value注解. 使用Environment. @ConfigurationProperties注解. 通过实现ApplicationListener接口,注册监听器,进行硬编码获取,可参考https://blog.csdn.net/thc1987/article/details/7…
package com.JUtils.beanConvert; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.M…
import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap;…
一.转换 1.1.TreeMap 有序Map 无序有序转换 使用默认构造方法: public TreeMap(Map<? extends K, ? extends V> m) 1.2.Map和Bean互转 BeanUtils位于org.apache.commons.beanutils.BeanUtils下面,其方法populate的作用解释如下: 完整方法: BeanUtils.populate( Object bean, Map properties ), 这个方法会遍历map<key…
报错: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'comp…
一.解析json之net.sf.json 下载地址 使用netsfjson需要导入的包 JSONObject JSONArray JavaBean与json字符串互转 List与json字符串互转 Map与json字符串互转 JSONArray与List互转 JSONArray与数组互转 XML与JSON互转 下载地址 本次使用版本:http://sourceforge.net/projects/json-lib/files/json-lib/json-lib-1.1/ 最新版本:http://…
xml与map互转,主要使用dom4j import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.slf4j.Logger; import org.slf4j.L…
1,JSONObject json对象,就是一个键对应一个值,使用的是大括号{ },如:{key:value} 2,JSONArray json数组,使用中括号[ ],只不过数组里面的项也是json键值对格式的 Json对象中添加的是键值对,JSONArray中添加的是Json对象 import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.junit.Test; import java.util.ArrayLi…
有不少工具类给bean填充值.但是填充,很多都是只能填充到当前类的对象.经过需求修改,做了个工具类: import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.iafclub.baseTools.vo.P…
1.//查询整个对象String hql="from Users";Query query = session.createQuery(hql);List<Users> users = query.list();for(Users user: users){System.out.print(user.getName()+" "+user.getPassword());}} 输出结果为: name1 : password1 : 1 name2 : pass…
1.list转setSet set = new HashSet(new ArrayList()); 2.set转listList list = new ArrayList(new HashSet()); 3.数组转为listList stooges = Arrays.asList("Larry", "Moe", "Curly");或者String[] arr = {"1", "2"};List list =…
1.list转set Set set =  new  HashSet( new  ArrayList()); 2.set转list List list =  new  ArrayList( new  HashSet()); 3.数组转为list List stooges = Arrays.asList( "Larry" ,  "Moe" ,  "Curly" ); 此时stooges中有有三个元素.注意:此时的list不能进行add操作,否则会报…
public static <T> T converter(Map<String, Object> map, Class<T> clz) { T obj = null; try { obj = clz.newInstance(); BeanInfo beanInfo = Introspector.getBeanInfo(clz); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescrip…
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.28</version> </dependency> public class User { private String name; private Integer age; private String sex; public…
今天启动srpingmvc项目的时候出现了这个异常, 原因: 在同个项目中,我复制了其中一个 Controller 作为备份 却忘记修改  @RequestMapping("/xxx") 在springmvc中不能同时映射一个名字(@RequestMapping("/xxx")  …
springMVC报错,原因方法之间@RequestMapping()到了同一个地址,导致springmvc无法定位…
//[字符串]转成[数组] String[] arr = "1,2,3,4,5,6".split(","); //[String数组]转成[Long数组] Long[] LongIds= (Long[]) ConvertUtils.convert(arr, Long.class); //[数组] 转 [ArrayList] ArrayList<Long> ids = new ArrayList<Long>(Arrays.asList(Long…
在www.json.org上公布了很多JAVA下的json构造和解析工具,其中org.json和json-lib比较简单,两者使用上差不多但还是有些区别.下面接着介绍用org.json构造和解析Json数据的方法示例.       用json-lib构造和解析Json数据的方法详解请参见我上一篇博文:Java构造和解析Json数据的两种方法详解一 一.介绍 org.json包是另一个用来beans,collections,maps,java arrays 和XML和JSON互相转换的包,主要就是…
在www.json.org上公布了很多JAVA下的json构造和解析工具,其中org.json和json-lib比较简单,两者使用上差不多但还是有些区别.下面接着介绍用org.json构造和解析Json数据的方法示例.       用json-lib构造和解析Json数据的方法详解请参见我上一篇博文:Java构造和解析Json数据的两种方法详解一 一.介绍       org.json包是另一个用来beans,collections,maps,java arrays 和XML和JSON互相转换的…
转自:http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/24/3096437.html 在www.json.org上公布了很多JAVA下的json构造和解析工具,其中org.json和json-lib比较简单,两者使用上差不多但还是有些区别.下面接着介绍用org.json构造和解析Json数据的方法示例.       用json-lib构造和解析Json数据的方法详解请参见我上一篇博文:Java构造和解析Json数据的两种方法详解一 一.介…
给自己做个笔记... 有时会用到配置文件中配置一下映射关系,方便以后扩展.此时可采用集合类型的bean配置方式配置.程序中直接注入即可. map类型的: <!-- 旧版方式,无需util包 --> <bean id="emails" class="org.springframework.beans.factory.config.MapFactoryBean"> <property name="sourceMap"&g…
参考:http://www.kaifajie.cn/spring/9966.html <bean id="fieldMap" class="org.springframework.beans.factory.config.MapFactoryBean"> <property name="sourceMap"> <map> <entry key="title" value-ref=&qu…
Dao层代码: package com.it.dao; public interface SayHell { public void sayHello(); } Dao的Impl实现层: package com.it.dao.impl; import java.util.List; import java.util.Map; import com.it.dao.SayHell; /** * Spring如何知道setter方法?如何将值注入进去的呢?其实方法名是要遵守约定的,setter注入的方…
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱好者,互联网技术发烧友 微博:伊直都在0221 QQ:951226918 -----------------------------------------------------------------------------------------------------------------…
简单的map转换成Bean的工具 package com.sd.microMsg.util; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; imp…