背景:想对字符串进行格式化,前面补零操作,代码如下:
if (!StringUtils.equals("0", areaCode.getCity()) && StringUtils.equals("0", areaCode.getArea()) && StringUtils.equals("0", areaCode.getTown())) {
// 市级
BeanUtils.copyProperties(areaCode, tourAreaInfo);
tourAreaInfo.setLevel("2");
tourAreaInfo.setPcode(String.format("%06d", areaCode.getProvince()));
}
结果报错:
Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.String
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2793)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2747)
at java.util.Formatter.format(Formatter.java:2520)
at java.util.Formatter.format(Formatter.java:2455)
at java.lang.String.format(String.java:2940)
at com.portrail.city.area.model.AreaCode.convert2JwTourAreaInfo(AreaCode.java:33)
at com.portrail.city.area.service.JwTourAreaInfoService.lambda$initAreaCode$1(JwTourAreaInfoService.java:53)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.portrail.city.area.service.JwTourAreaInfoService.initAreaCode(JwTourAreaInfoService.java:53)
at com.portrail.city.area.service.JwTourAreaInfoService.main(JwTourAreaInfoService.java:66)
出错原因,d
表示对整型进行转换格式,传入的却是字符串。
实现方式改为: Java字符串右侧补零实现。
最新评论
网飞没问题, 迪士尼+有解决方案么?
pp助手是安卓手机用的,根本下载用不来苹果
已解决
这样的话数据库里的结构为{"attachment":{"content":"xxx"}}, 要怎么才能变成{"content":"xxx"},从而使结构保持一致?
赞! make test不过的坑都写到的,谢谢楼主~
谢谢你
用了root用户还是一直502是怎么回事呢
student id 是空的