页面全部都是HTML的,没有JSP页面。
在前台会有一个业务相关的调查问卷需要客户去填写,当客户选择"是"的时候,需要对调查问卷上的所选择"是"的问题作出相对应的详细描述.选择"否"则不需要.
现在遇到的问题就是不知道怎么去获取用户选择和输入的内容,然后存到数据库里面.
因为不论是和否,都是要存到数据库的.而数据库中有两张关联表,一个是问题表,一个是答案表.问题表中的id于答案表中的questionId是关联的.求助各位大佬,怎么才能获取到用户输入和选择的内容,并通过ajax传到后台,再保存到数据库呢?
这是自己的写的保存的操作,也不知道对不对
$(function () {
var aiEdorTemporary = sessionStorage.aiEdorTemporary;
if(hasValue(aiEdorTemporary)){
aiEdorTemporary = JSON.parse(aiEdorTemporary);
}
var ids = sessionStorage.imageIds;
aiEdorTemporary.transNo=ids;
$.ajax({
type:"POST",
async : false,
contentType : "application/json;charset=utf-8",
data:JSON.stringify(aiEdorTemporary),
url:"/inform/doSave",
success:function(data){
if(data.result=="0"){
sessionStorage.resultCode = 0;
sessionStorage.resultMsgTitle = "success1";
sessionStorage.resultNextUrl = "close";
}else{
sessionStorage.resultCode = 1;
sessionStorage.resultMsg = data.msg;
sessionStorage.resultNextUrl = "close";
}
window.location.href = "/View/allin/inform/inform_isUpload.html";
},
})
})
这是在controller里面写的保存数据库操作
@Autowired@Autowired
AiNotifyQuestionService aiNotifyQuestionService;
@ResponseBody
@RequestMapping(value="/doSave",method = RequestMethod.POST, consumes ="application/json")
public Map<String, String> doSave(@RequestBody AiNotifyQuestion aiNotifyQuestion,HttpServletRequest request){
Map<String, String> dataMap = new HashMap<String, String>();
try {
AiNotifyRelation aiNotifyRelation = (AiNotifyRelation) request.getSession().getAttribute("aiNotifyRelation");
if(aiNotifyRelation == null){
dataMap.put("result", "-4");
return dataMap;
}
//aiNotifyRelation答案实体类对象
aiNotifyRelation.setId(aiNotifyRelation.getId());
aiNotifyRelation.setEdorAcceptNo(aiNotifyRelation.getEdorAcceptNo());
aiNotifyRelation.setQuestionContent(aiNotifyRelation.getQuestionId());
aiNotifyRelation.setQuestionId(aiNotifyRelation.getQuestionContent());
aiNotifyRelation.setMakeDate(aiNotifyRelation.getMakeDate());
aiNotifyRelation.setLastModifyDate(aiNotifyRelation.getLastModifyDate());
//aiNotifyQuestion 问题实体类对象
aiNotifyQuestion.setId(aiNotifyQuestion.getId());
aiNotifyQuestion.setRisk_Code(aiNotifyQuestion.getRisk_Code());
aiNotifyQuestion.setImpartTypeName(aiNotifyQuestion.getImpartTypeName());
aiNotifyQuestion.setImpartType(aiNotifyQuestion.getImpartType());
aiNotifyQuestion.setImpartVersion(aiNotifyQuestion.getImpartVersion());
aiNotifyQuestion.setImpartVersion(aiNotifyQuestion.getImpartVersion());
aiNotifyQuestion.setImpartCode(aiNotifyQuestion.getImpartCode());
aiNotifyQuestion.setInformContent(aiNotifyQuestion.getImpartCode());
aiNotifyQuestion.setStartDate(aiNotifyQuestion.getStartDate());
aiNotifyQuestion.setEndDate(aiNotifyQuestion.getEndDate());
aiNotifyQuestion.setStatus(aiNotifyQuestion.getStatus());
aiNotifyQuestion.setInformOrder(aiNotifyQuestion.getInformOrder());
aiNotifyQuestion.setMakeDate(aiNotifyQuestion.getMakeDate());
aiNotifyQuestion.setLastModifyDate(aiNotifyQuestion.getLastModifyDate());
com.hk.allin.axis.vo.webEdorHangUpBL.response.TransData td = aiNotifyQuestionService.webEdorHangUpBL(aiNotifyQuestion.getId(),list);
Map<String, String> res = AiEdorInputService.getResult(td);
if(res==null || !"0".equals(res.get("resultCode"))){
AiEdorLog.INFO("挂起接口返回失败,"+aiNotifyQuestion.getId()+","+aiNotifyQuestion.getInformContent()+","+res.get("resultMsg"));
dataMap.put("result", "1");
dataMap.put("msg", "系统异常");
return dataMap;
}
Map<String, String> no = AiEdorInputService.getData(td);
aiNotifyQuestion.setImpartCode(no.get(aiNotifyQuestion.getImpartCode()));
aiNotifyQuestionService.add(aiNotifyQuestion);
dataMap.put("result", "0");
} catch (Exception e) {
dataMap.put("msg", "系统繁忙,请稍候再试!");
dataMap.put("result", "1");
}
return dataMap;
}
这是问题表
这是答案表.