java.lang.NumberFormatException: For input string: “method:{0}.{1}“处理

写测试时用占位符 MessageFormat.format 输出报错
在这里插入图片描述
仔细查看了一下我的语句

 System.out.println(MessageFormat.format(
                "{method:{0}.{1},params:{2},user:[id:{3},username:{4}],ip:{5},dateTime:{6},operationCode:{7},type:{8},creater:{9},requestUrl:{10}}"
                ,cla,method,json.toString(),userid,username,ip,new Date().getTime(),"ceshi",request.getMethod(),"ceshiCreater",request.getRequestURL()));

发现format不允许{…{0}…}这样的形式,然后我改成了…{0}…

System.out.println(MessageFormat.format(
                "method:{0}.{1},params:{2},user:[id:{3},username:{4}],ip:{5},dateTime:{6},operationCode:{7},type:{8},creater:{9},requestUrl:{10}"
                ,cla,method,json.toString(),userid,username,ip,new Date().getTime(),"ceshi",request.getMethod(),"ceshiCreater",request.getRequestURL()));

运行成功了

像这一类的错误都是非常小的点,只能多经历才能避免了

猜你喜欢

转载自blog.csdn.net/weixin_44077556/article/details/108342472