用map添加报错writemapnullvalue求解

//ConcurrentHashMap源码: /** Implementation for put and putIfAbsent */
final V putVal(K key, V value, boolean onlyIfAbsent) {
if (key == null || value == null) throw new NullPointerException();
关于为什么这么设计:
https://laiqitech.com/125/
关于null的一些小知识:
http://www.importnew.com/14229.html
阅读(...) 评论()mybatis中 传入map 其中value位integer的0,为什么变成了null
[问题点数:40分]
mybatis中 传入map 其中value位integer的0,为什么变成了null
[问题点数:40分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
在看理解ES6 Map时,根据书的代码敲。发现清除引用后,虽然map.has(key)已经是false,但是console.log(map)时却有两种结果。代码如下:
let map = new WeakMap(),
element = document.querySelector('.ele'),
element2 = document.querySelector('.ele2');
map.set(element, 'sss');
let value = map.get(element);
console.log(value);
// 移除该元素
element.parentNode.removeChild(element);
console.log(map)
控制台输出结果1:
有时结果又是:
如果是添加两个键值对,然后清除其中一个的引用
let map = new WeakMap(),
element = document.querySelector('.ele'),
element2 = document.querySelector('.ele2');
map.set(element, 'sss');
map.set(element2, '222');
let value = map.get(element);
let value2 = map.get(element2);
console.log(value);
console.log(value2);
// 移除该元素
element.parentNode.removeChild(element);
console.log(map)
// 只有一个element时, map [[Entries]]: Array(0) 有时又不是空
//WeakMap {div.ele =& "sss", div.ele2 =& "222"} 为什么?
// 都不能访问到
输出也是会有两种结果
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。java中private Map&String,List&实体&& names= 这样调用的时候会出现空指针异常,求如何初始化_百度知道
java中private Map&String,List&实体&& names= 这样调用的时候会出现空指针异常,求如何初始化
我有更好的答案
names = new HashMap&String,List&实体&&
private 中已近不能new了
你在哪里定义private为什么不能new
采纳率:33%
1.因为你只是 声明了一个对象啊,可以理解为一个虚拟的东东,也可以理解为一个遥控器,此时未给他匹配一个电视机,那么你操作遥控器有作用么?2.只有创建(new)了以后,才给这个对象分配内存, 这时候就是一个具体的东东,你才能使用他. 此时给他指定了一个电视机,那么你就可以操作遥控器了,而且效果很好.3.java里创建对象很简单, 就是用new4.你的这个可以写成
new HashMap&String,List&实体&&();5.谁说private 不能new了?
names为null,肯定空指针了。初始化,例如: Map&String,List&String&& names= names = new HashMap&String,List&String&& ();List&String&&
list = new ArrayList&String&();list.add('1');list.add('2');names.put(&a&,list);names.put(&b&,list);仅供参考!
private Map&String,List&实体&& names=new HashMap&String,ArrayList&实体&&();
Map要初始化,每个key对应的Value里面的List也要初始化
可以的new 的
其他3条回答
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。博客分类:
错误信息:
SQLErrorCodesFactory - Database product name cached for DataSource [org.apache.commons.dbcp.BasicDataSource@19c5048]: name is 'MySQL'SQLErrorCodesFactory - SQL error codes for 'MySQL' foundSQLErrorCodeSQLExceptionTranslator - Unable to translate SQLException with Error code '0', will now try the fallback translatorDataSourceUtils - Returning JDBC Connection to DataSourceException in thread "main" org.springframework.jdbc.UncategorizedSQLException: SqlMapC uncategorized SQLException for SQL []; SQL state [null]; error code [0]; --- The error occurred in net/jbbs/dao/ibatis/map/user.xml. --- The error occurred while applying a result map. --- Check the user.userResult. --- The error happened while setting a property on the result object. --- Cause: net.sf.cglib.beans.BulkBeanE nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in net/jbbs/dao/ibatis/map/user.xml. --- The error occurred while applying a result map. --- Check the user.userResult. --- The error happened while setting a property on the result object. --- Cause: net.sf.cglib.beans.BulkBeanExceptionCaused by: com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in net/jbbs/dao/ibatis/map/user.xml. --- The error occurred while applying a result map. --- Check the user.userResult. --- The error happened while setting a property on the result object. --- Cause: net.sf.cglib.beans.BulkBeanExceptionat com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:566)at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541)at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:243)at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:193)at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:241)at net.jbbs.dao.ibatis.UserDAOImpl.findByEmail(UserDAOImpl.java:54)at net.jbbs.test.UserTest.findByEmail(UserTest.java:42)at net.jbbs.test.UserTest.main(UserTest.java:34)Caused by: net.sf.cglib.beans.BulkBeanExceptionat net.jbbs.domain.User$$BulkBeanByCGLIB$$88b6b34d.setPropertyValues(&generated&)at com.ibatis.sqlmap.engine.accessplan.EnhancedPropertyAccessPlan.setProperties(EnhancedPropertyAccessPlan.java:33)at com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:112)at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:373)at com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:64)at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:382)at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:301)at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:190)at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)... 10 more
这个错误指出resultMap里有问题。说错误发生在设置某一个属性的时候,但是没有具体说明是一个怎么样的错误&NULL错误&。由于对于iBatis了解还不是很深,所以一时不知如何事好。只有在resultMap里面作文章,把里面的&result&注释掉一些,哈哈,程序居然正常跑起来了。看来我快要找到错误了,接着继续排除其它的&result&,终于让我找到出错的一行&result&了:&result column="ORDER_NUM" property="orderNum" jdbcType="long" /&&!--  接下来得弄清楚是一个什么样的错误,怎么去修复它。查找数据库表,发现"orderNum"这一列是nullable,并且没有为它设置默认值。所以表里面orderNum这一列有许多都为NULL。我大概明白了,肯定是iBatis试图把从数据库读出来的NULL 值写入对象属性的时候出现异常。采取的补救措施就是:&result column="ORDER_NUM" property="orderNum" jdbcType="long" nullValue="0"/&对从数据库读出来的NULL值采用一个相应可转换为orderNum类型的值来替换附:&resultMap id="pageStaticItemMap" class="PageStaticItem"&&result column="ITEMID" property="itemId" jdbcType="long"/&&result column="ITEMNAME" property="itemName" jdbcType="String"/&&result column="SERVERID" property="serverId" jdbcType="long"/&&result column="SOURCE" property="source" jdbcType="String"/&&result column="TARGET_PATH" property="targetPath" jdbcType="String"/&&result column="TARGET_FILE" property="targetFile" jdbcType="String"/&&result column="LOCAL_PATH" property="localPath" jdbcType="String"/&&result column="FTP_PATH" property="ftpPath" jdbcType="String"/&&result column="ITEMTYPE" property="itemType" jdbcType="String"/&&result column="EXT1" property="ext1" jdbcType="String"/&&result column="EXT2" property="ext2" jdbcType="String"/&&result column="EXT3" property="ext3" jdbcType="String"/&&result column="EXT4" property="ext4" jdbcType="String"/&&result column="ORDER_NUM" property="orderNum" jdbcType="long" /&&!--这一行加一个nullValue="0"就OK了--&&result column="ITEM_TYPE" property="item_Type" jdbcType="String"/&&result column="SERVER_PROPERTIES" property="serverProperties" jdbcType="String"/&&result column="GET_SQL" property="getSql" jdbcType="String"/&&/resultMap&
浏览: 55999 次
来自: 上海
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'

我要回帖

更多关于 map put null 的文章

 

随机推荐