package com.lovenav.controller; import com.lovenav.entity.Config; import com.lovenav.service.AttachmentService; import com.lovenav.service.ConfigService; 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.RestController; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; @RestController public class ConfigController { //配置文件操作 @Autowired ConfigService configService; @Autowired AttachmentService attachmentService; @RequestMapping("/updateConfig") public String updateConfig(Config config){ Date date=new Date(); try { config.setUpdatetime(date.getTime()); if (config.getName().equals("")||config.getValue().equals("")){ return "配置文件不能为空!"; } if (configService.updateConfig(config)==1){ return "更新成功!"; } else if (configService.updateConfig(config)==2){ return "不存在名称为"+config.getName()+"的配置文件,请先添加!"; } return "更新失败!";}catch (NullPointerException e){ return "请输入配置信息!"; } } @RequestMapping("/addConfigString") public String addConfig(Config config){ try { if (config.getName().equals("")||config.getValue().equals("")){ return "属性值不能为空"; }else { Date date=new Date(); config.setUpdatetime(date.getTime()); return configService.addConfig(config); } }catch (NullPointerException e){ return "请输入配置信息"; } } @RequestMapping("/getAllEmailConfig") public HashMap getAllEmailConfig(){ return configService.selectEmailConfig(); } @RequestMapping("/getConfig") public HashMap getAllEmailConfig(Config config){ HashMap map=new HashMap<>(); Config config1; config1 =configService.selectAlreadyExist(config); if (config1!=null){ map.put(config1.getName(),config1); return map; }else { map.put("msg","没有该配置!"); return map; } } }