Browse Source

answer初始化option为空而不是-1

xujiawei 6 years ago
parent
commit
68db2c95c8

+ 2 - 0
src/main/java/edu/nju/controller/ExtraController.java

@@ -451,11 +451,13 @@ public class ExtraController {
 	@ResponseBody
 	public void uploadExamUrl(String jobJson, HttpServletResponse response) {
 		try {
+//			System.out.println(jobJson);
 			PrintWriter out = response.getWriter();
 			JSONObject result = new JSONObject();
 			String job_id = extraService.saveJob(jobJson);
 			result.put("id", job_id);
 			out.print(result);
+//			out.print("success");
 			out.flush();
 			out.close();
 		} catch (IOException e) {

+ 9 - 2
src/main/java/edu/nju/controller/ItemController.java

@@ -125,9 +125,16 @@ public class ItemController {
 
     @RequestMapping(value = "/updateAnswer", method = RequestMethod.POST)
     @ResponseBody
-    public void updateAnswer(String id, String item_id, String worker_id, String job_id, @RequestParam("answers")List<String>answers,@RequestParam("attachment_location") List<String> attachment_location, HttpServletResponse response){
+    public void updateAnswer(String id, @RequestParam("answers")List<String>answers,@RequestParam("attachment_location") List<String> attachment_location, HttpServletResponse response){
+        System.out.println(id);
+//        System.out.println(item_id);
+//        System.out.println(worker_id);
+//        System.out.println(job_id);
+        System.out.println(answers);
+        System.out.println(attachment_location);
+
         JSONObject result = new JSONObject();
-        if(iservice.updateAnswer(id, item_id, worker_id, job_id, answers, attachment_location)){
+        if(iservice.updateAnswer(id, answers, attachment_location)){
             result.put("status", "200");
         } else {
             result.put("status", "500");

+ 8 - 0
src/main/java/edu/nju/dao/AnswerDao.java

@@ -37,4 +37,12 @@ public class AnswerDao {
         mongoOperations.save(answer);
         return answer.getId();
     }
+
+    public Answer getAnswerById(String id){
+        Query query = new Query();
+        query.addCriteria(Criteria.where("_id").is(id));
+        List<Answer> list = mongoOperations.find(query, Answer.class);
+        if(list.size() == 0 || list == null) {return null;}
+        return list.get(0);
+    }
 }

+ 5 - 3
src/main/java/edu/nju/service/ItemService.java

@@ -51,11 +51,13 @@ public class ItemService {
         return answerDao.save(answer);
     }
 
-    public boolean updateAnswer(String id, String item_id, String worker_id, String job_id, List<String>answers,List<String> attachment_location){
+    public boolean  updateAnswer(String id, List<String>answers,List<String> attachment_location){
         try {
             if(id == null || id.equals("undefined")) { return false; }
-            Answer answer=new Answer(item_id,answers,worker_id,attachment_location,job_id);
-            answer.setId(id);
+            Answer answer=answerDao.getAnswerById(id);
+//            answer.setId(id);
+            answer.setAnswers(answers);
+            answer.setAttachment_location(attachment_location);
             answerDao.save(answer);
             return true;
         } catch(Exception e) {