action部分:
String questionkindId;
String questionCon;
String choicea;
String choiceb;
String choicec;
String choiced;
String result;
生成getter和setter方法,由于应用了ssh框架,因此只要在action中定义与JSP页面中name名称相同的属性,并生成setter和getter,并在JSP中定义即可自动获取JSP表单中的内容。
public String AddQuestion_wanxing(){
for(int i=0;i
if(success) return "success";
else return "failure";
}
return "failure";
}
service层:
public Boolean AddQuestion_wanxing(String questionkindId,
String questionCon, String[] choiceas, String[] choicebs,
String[] choicecs, String[] choiceds, String[] results,
String[] questionAnas, String[] questionknows, String errorRate,
String difficult, String[] questionDetailIds);
serviceimplement层:
public Boolean AddQuestion(String questionkindId, String questionCon,
String choicea, String choiceb, String choicec, String choiced,
String result, String questionAna, String questionknow,String errorRate,String difficult,String QuestionDetailId) {
try {
return questiondao.AddQuestion(questionkindId, questionCon, choicea, choiceb, choicec, choiced, result, questionAna, questionknow,errorRate,difficult,QuestionDetailId);
} catch (Exception e) {
// TODO: handle exception
return false;
}
}
dao层:
public Boolean AddQuestion_wanxing(String questionkindId,
String questionCon, String[] choiceas, String[] choicebs,
String[] choicecs, String[] choiceds, String[] results,
String[] questionAnas, String[] questionknows, String errorRate,
String difficult, String[] questionDetailIds);
daoimplement层:
public Boolean AddQuestion(String questionkindId, String questionCon,
String choicea, String choiceb, String choicec, String choiced,
String result, String questionAna, String questionknow,String errorRate,String difficult,String QuestionDetailId) {
// TODO Auto-generated method stub
try {
Question question=new Question();
question.setQuestionKind(Integer.parseInt(questionkindId));
question.setQuestionCon(questionCon);
question.setQuestionErrorRate(Float.valueOf(errorRate));
question.setQuestionDifficult(Integer.parseInt(difficult));
if((Integer.parseInt(questionkindId))==1){
question.setQuestionNumber(1);}
else if((Integer.parseInt(questionkindId))==2){
question.setQuestionNumber(20);
}
else if((Integer.parseInt(questionkindId))==3){
question.setQuestionNumber(5);
}
// QuestionDetail detail=(QuestionDetail) question.getQuestionDetails();
QuestionDetail detail = new QuestionDetail();
int detailid=Integer.parseInt(QuestionDetailId);
QuestionDetailId ID = new QuestionDetailId(question, detailid);
detail.setId(ID);
detail.setSelectA(choicea);
detail.setSelectB(choiceb);
detail.setSelectC(choicec);
detail.setSelectD(choiced);
detail.setSelectans(result);
detail.setSelectExplain(questionAna);
detail.setSelectKnowledge(questionknow);
question.getQuestionDetails().add(detail);
getHibernateTemplate().save(question);
return true;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return false;
}
}
JSP页面部分:
新增题目
bean.XML部分
struct.xml部分: