Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package controllers; import data.services.ParseBaseService; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import support.StringAdapter; /** * * @author bezdatiuzer */ @Controller @RequestMapping("/ParseBaseController") public class ParseBaseController { @Autowired ParseBaseService parseBaseService; @RequestMapping("/show") public String showParseForm(Map<String, Object> model) throws Exception { return "ParseBaseShow"; } @RequestMapping("/addFile") public String addFile(Map<String, Object> model, @RequestParam("newFile") MultipartFile file) throws IOException { File newFile = new File("/usr/local/etc/qutoCatalog.sql"); //++? ??? if (!newFile.exists()) { FileUtils.writeByteArrayToFile(newFile, file.getBytes()); } else { newFile.delete(); FileUtils.writeByteArrayToFile(newFile, file.getBytes()); } return "redirect:/ParseBaseController/show"; } @RequestMapping("/copy") public String copyQutoParams(Map<String, Object> model) throws Exception { //++? ? List<String> erList = new ArrayList(); try { parseBaseService.updateDataFromQuto(); erList = parseBaseService.getResult().getErrors(); } catch (Exception e) { erList = parseBaseService.getResult().getErrors(); erList.add(StringAdapter.getStackTraceException(e)); } model.put("error", erList); return "ParseBaseShow"; } }