如何在angularjs中切换到生产模式以进行无服务器开发?

时间:2019-02-02 09:31:09

标签: javascript angularjs

我使用 @RequestMapping("uploadQuestion") public String uploadQuestion(@RequestParam("file") MultipartFile file, @RequestParam Long examId, Model model, HttpSession session) throws IOException, InvalidFormatException { int flag = 0; String id = (String) session.getAttribute("userId"); model.addAttribute("examList", onlineExamMasterRepository.findAll()); DataFormatter formatter = new DataFormatter(); List<OnlineExamQuestionMaster> quetions = new ArrayList<OnlineExamQuestionMaster>(); List<OnlineExamOptionMaster> options = new ArrayList<OnlineExamOptionMaster>(); if (file.isEmpty()) { model.addAttribute("info", "Please select a file to upload"); return "onlinexam/questionUpload :: section"; } InputStream in = file.getInputStream(); XSSFWorkbook workbook = new XSSFWorkbook(in); XSSFSheet sheet = workbook.getSheetAt(0); Row row; System.out.println(sheet.getLastRowNum()); for (int i = 1; i <= sheet.getLastRowNum(); i++) { OnlineExamQuestionMaster qm = new OnlineExamQuestionMaster(); OnlineExamQuestionMasterPK qmp = new OnlineExamQuestionMasterPK(); OnlineExamOptionMasterPK omp[] = new OnlineExamOptionMasterPK[4]; OnlineExamOptionMaster om[] = new OnlineExamOptionMaster[4]; qmp.setExamId(examId); qm.setLogTimestamp(new Date()); qm.setLogUserid(id); flag++; row = (Row) sheet.getRow(i); System.out.println(row.getCell(0).toString()); if (row.getCell(0).toString().equals(null)) { model.addAttribute("info", "Some columns are null please check and try"); return "onlinexam/questionUpload :: section"; } else { qmp.setQuestionId(Long.parseLong(formatter.formatCellValue(row.getCell(0)))); if (onlineExamQuestionMasterRepository.exists(qmp)) { model.addAttribute("message", "Already QuestionId with " + formatter.formatCellValue(row.getCell(0)) + " Exist for ExamId " + examId); return "onlinexam/questionUpload :: section"; } } if (row.getCell(1).toString().equals("")) { model.addAttribute("info", "Some columns are null please check and try"); return "onlinexam/questionUpload :: section"; } else { row = (Row) sheet.getRow(i); Iterator<Cell> iterator2 = row.cellIterator(); /*XSSFWorkbook workbook2 = sheet.getWorkbook(); List<XSSFPictureData> pictures = workbook2.getAllPictures(); Iterator<XSSFPictureData> iterator = pictures.iterator();*/ while(iterator2.hasNext()) { PictureData pictureData = (PictureData)iterator2.next(); String fileextension = pictureData.suggestFileExtension(); byte[] data = pictureData.getData(); if(fileextension.equals("jpeg")) { qm.setImage(data);; } else qm.setQidDescription(row.getCell(1).toString().trim()); } } if (row.getCell(2).toString().equals("")) { model.addAttribute("info", "Some columns are null please check and try"); return "onlinexam/questionUpload :: section"; } else { omp[0] = new OnlineExamOptionMasterPK(); om[0] = new OnlineExamOptionMaster(); omp[0].setQid(Long.parseLong(formatter.formatCellValue(row.getCell(0)))); omp[0].setOptionId("A"); omp[0].setExamId(examId); om[0].setLogTimestamp(new Date()); om[0].setLogUserid(id); om[0].setOptionDesc(row.getCell(2).toString().trim()); om[0].setId(omp[0]); } if (row.getCell(3).toString().equals("")) { model.addAttribute("info", "Some columns are null please check and try"); return "onlinexam/questionUpload :: section"; } else { omp[1] = new OnlineExamOptionMasterPK(); om[1] = new OnlineExamOptionMaster(); omp[1].setExamId(examId); omp[1].setQid(Long.parseLong(formatter.formatCellValue(row.getCell(0)))); omp[1].setOptionId("B"); om[0].setLogTimestamp(new Date()); om[0].setLogUserid(id); om[1].setOptionDesc(row.getCell(3).toString().trim()); om[1].setId(omp[1]); } if (row.getCell(4).toString().equals("")) { model.addAttribute("info", "Some columns are null please check and try"); return "onlinexam/questionUpload :: section"; } else { omp[2] = new OnlineExamOptionMasterPK(); om[2] = new OnlineExamOptionMaster(); omp[2].setExamId(examId); omp[2].setQid(Long.parseLong(formatter.formatCellValue(row.getCell(0)))); omp[2].setOptionId("C"); om[0].setLogTimestamp(new Date()); om[0].setLogUserid(id); om[2].setOptionDesc(row.getCell(4).toString().trim()); om[2].setId(omp[2]); } if (row.getCell(5).toString().equals("")) { model.addAttribute("info", "Some columns are null please check and try"); return "onlinexam/questionUpload :: section"; } else { omp[3] = new OnlineExamOptionMasterPK(); om[3] = new OnlineExamOptionMaster(); omp[3].setExamId(examId); omp[3].setQid(Long.parseLong(formatter.formatCellValue(row.getCell(0)))); omp[3].setOptionId("D"); om[0].setLogTimestamp(new Date()); om[0].setLogUserid(id); om[3].setOptionDesc(row.getCell(5).toString().trim()); om[3].setId(omp[3]); } if (row.getCell(6).toString().equals("")) { model.addAttribute("info", "Some columns are null please check and try"); return "onlinexam/questionUpload :: section"; } else { qm.setAnswer(row.getCell(6).toString().toUpperCase().trim()); } if (row.getCell(7).toString().equals("")) { model.addAttribute("info", "Some columns are null please check and try"); return "onlinexam/questionUpload :: section"; } else { qm.setMarks(Long.parseLong(formatter.formatCellValue(row.getCell(7)))); } qm.setId(qmp); quetions.add(qm); options.addAll(Arrays.asList(om)); } for (OnlineExamQuestionMaster h : quetions) { onlineExamQuestionMasterRepository.save(h); } System.out.println(options.size()); for (OnlineExamOptionMaster h : options) { System.out.println(h.toString()); onlineExamOptionMasterRepository.save(h); } model.addAttribute("info", flag + "Questions Uploaded Sucessfully"); return "onlinexam/questionUpload :: section"; } 进行开发。我使用angular-mock。 我需要帮助组织生产和开发模式之间的切换。 对不起,我的英语。

webpack
angular.module('userModule', ['userModuleMock'])
  .factory('userService', userService);

userService.$inject = ['$http'];

function userService($http) {
  return {
    getAll: function() {
      return $http.get('/api/v1/users');
    }
  };
}

angular.module('userModuleMock', ['ngMockE2E'])
  .run(userServiceMock);

userServiceMock.$inject = ['$httpBackend'];

function userServiceMock($httpMock) {
    var users = [
      {
        name: 'John'
      },
      {
        name: 'Mary'
      }
    ];
    $httpMock.whenGET('/api/v1/users').respond(users);
}

angular.module('app', ['userModule'])
  .controller('appController', appController);

appController.$inject = ['userService'];

function appController(userService) {
  userService.getAll()
    .then(function(response) {
      console.log(response.data);
    })
    .catch(function(err) {
      throw err;
    });
}

angular.bootstrap(
  document.getElementById('root'),
  ['app']
);

0 个答案:

没有答案