我想将数据保存到主 - 详细信息表中。第一部分用于主表,最后部分用于详细信息表。我有java.lang.String无法强制转换为[Ljava.lang.String。如何恢复从这个问题。如何将map.get(" step_id []")分配到字符串数组String [] WfIds。我想将每个值分配给不同的字符串数组。
控制器代码
Map<String,Object> wfManager = new HashMap<String,Object>();
// ************************从视图发送的主数据**************** ************** //
wfManager.put("workflow_code",(request.getParameter("workflow_code")).toUpperCase());
wfManager.put("workflow_name",request.getParameter("workflow_name"));
wfManager.put("workflow_descr",request.getParameter("workflow_descr"));
wfManager.put("object_type_code",request.getParameter("object_type_code"));
// *********************从视图发送的详细项目数据****************** ************** //
wfManager.put("wf_block_id[]", request.getParameter("wf_block_id[]"));
wfManager.put("step_code[]" , request.getParameter("step_code[]"));
wfManager.put("step_name[]", request.getParameter("step_name[]"));
wfManager.put("doa_type_code[]", request.getParameter("doa_type_code[]"));
wfManager.put("doa_type_name[]", request.getParameter("doa_type_name[]"));
服务代码
public Map<String, String> insert(Map<String, Object> map) {
// ************************从视图发送的主数据**************** ************** //
Map<String, String> data = new HashMap<String, String>();
Workflow wf = new Workflow();
wf.setWorkflowCode((String)map.get("workflow_code"));
wf.setWorkflowName((String)map.get("workflow_name"));
wf.setWorkflowDescr((String)map.get("workflow_descr"));
wf.setObjectTypeCode((String)map.get("object_type_code"));
String[] WfIds = (String[]) map.get("step_id[]");
String[] wfBlockIds = (String[]) map.get("wf_block_id[]");
String[] wfsCodes = (String[]) map.get("step_code[]");
String[] stepNames = (String[]) map.get("step_name[]");
String[] doaTypeCodes = (String[]) map.get("doa_type_code[]");
String[] doaTypeNames = (String[]) map.get("doa_type_name[]");
List<WorkflowDetails> wfDetailsList = new ArrayList<WorkflowDetails>();
for(int i = 0; i< wfsCodes.length; i++){
WorkflowDetails wfDetails = new WorkflowDetails();
wfDetails.setWorkflowCode(wf.getWorkflowCode());
wfDetails.setWorkflowName(wf.getWorkflowName());
wfDetails.setWorkflowDescr(wf.getWorkflowDescr());
wfDetails.setWorkflowObjectTypeCode(wf.getObjectTypeCode());
wfDetails.setWorkflowObjectTypeName(wf.getObjectTypeName());
wfDetailsList.add(i,wfDetails);
}
wf.setSteps(wfDetailsList);
id = workflowManagerDAO.insertDoc(wf);
data.put("id", id);
return data;
} DAO代码:
@Transactional
@Override
public String insertDoc(Workflow wfManager) {
for(int i = 0; i < wfManager.getSteps().size(); i++){
WorkflowDetails wfDetails = new WorkflowDetails();
wfDetails = wfManager.getSteps().get(i);
sessionfactory.getCurrentSession().save(wfDetails);
sessionfactory.getCurrentSession().flush();
}
String id = (String) sessionfactory.getCurrentSession().save(wfManager);
sessionfactory.getCurrentSession().flush();
return id;
}
答案 0 :(得分:0)
如果您绝对需要使用request.getParameter()
,则必须使用分隔符将数组转换为字符串,例如:转换此
String[] array = { "John", "Peter", "Paul" };
到这个
String plainTextArray = "John#Peter#Paul";
然后,您将能够将数组值作为String传递(getParameter()
理解的唯一类型)。
然后你可以像这样恢复它们
String[] restoredArray = request.getParameter("plainTextArray").split("#");
也许您想查看setAttribute()
和getAttribute()
,它可以存储任何对象(包括数组)。你可以从Difference between getAttribute() and getParameter()