[英]Integer - String conversion issue in Java
将字符串转换为整数的最佳方法是什么。
params.get("contractPriceId");
在这里我得到 Exception cannot cast Integer to String ...
public List<ContractPriceDetailVO> getContractPriceDetails(
Map<String, String> params) throws DAOException {
// Get the request object
HttpServletRequest request = FlexContext.getHttpRequest();
// Get the AppContext object
AppContext ac = SessionUtils.getAppContext(request);
SimpleDateFormat sdf = new SimpleDateFormat(ac.getDateFormat());
List<Object[]> resultList = new ArrayList<Object[]>();
if (params.get("specId") != null && params.get("specId").trim() != ""
&& params.get("effDate") != null
&& params.get("effDate").trim() != null)
resultList = contractPriceEJBService.getContractPriceDetails(ac,
params);
String contractPriceId = null;
if (params.get("contractPriceId") != null){
try{
contractPriceId = params.get("contractPriceId");
}
catch (Exception e){
logger.error("Exception in getting contractPriceId "+e.getMessage());
}
}
else{
contractPriceId = null;
}
你得到哪个例外?
通常我们使用,
int price = Integer.parseInt("7");
这将返回字符串的 int 值。
请将异常和错误放在问题中,以便我们对问题进行更多分析。
像这样改变它,它应该可以工作
contractPriceId = params.get("contractPriceId") +"";
从整数到字符串,String.valueOf(47)。
从字符串到整数,Integer.parseInt("47")。
为避免异常,请尝试 String.valueOf(params.get("contractPriceId"))。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.