Java tutorial
/* * Copyright 2005-2015 shopxx.net. All rights reserved. * Support: http://3936242.01p.com/ * License: http://3936242.01p.com/license */ package net.shopxx.plugin.ftpStorage; import java.util.HashMap; import java.util.Map; import javax.annotation.Resource; import net.shopxx.Message; import net.shopxx.controller.admin.BaseController; import net.shopxx.entity.PluginConfig; import net.shopxx.service.PluginConfigService; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.mvc.support.RedirectAttributes; @Controller("adminFtpStorageController") @RequestMapping("/admin/storage_plugin/ftp_storage") public class FtpStorageController extends BaseController { @Resource(name = "ftpStoragePlugin") private FtpStoragePlugin ftpStoragePlugin; @Resource(name = "pluginConfigServiceImpl") private PluginConfigService pluginConfigService; @RequestMapping(value = "/install", method = RequestMethod.POST) public @ResponseBody Message install() { if (!ftpStoragePlugin.getIsInstalled()) { PluginConfig pluginConfig = new PluginConfig(); pluginConfig.setPluginId(ftpStoragePlugin.getId()); pluginConfig.setIsEnabled(false); pluginConfig.setAttributes(null); pluginConfigService.save(pluginConfig); } return SUCCESS_MESSAGE; } @RequestMapping(value = "/uninstall", method = RequestMethod.POST) public @ResponseBody Message uninstall() { if (ftpStoragePlugin.getIsInstalled()) { pluginConfigService.deleteByPluginId(ftpStoragePlugin.getId()); } return SUCCESS_MESSAGE; } @RequestMapping(value = "/setting", method = RequestMethod.GET) public String setting(ModelMap model) { PluginConfig pluginConfig = ftpStoragePlugin.getPluginConfig(); model.addAttribute("pluginConfig", pluginConfig); return "/net/shopxx/plugin/ftpStorage/setting"; } @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(String host, Integer port, String username, String password, String urlPrefix, @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order, RedirectAttributes redirectAttributes) { PluginConfig pluginConfig = ftpStoragePlugin.getPluginConfig(); Map<String, String> attributes = new HashMap<String, String>(); attributes.put("host", host); attributes.put("port", String.valueOf(port)); attributes.put("username", username); attributes.put("password", password); attributes.put("urlPrefix", StringUtils.removeEnd(urlPrefix, "/")); pluginConfig.setAttributes(attributes); pluginConfig.setIsEnabled(isEnabled); pluginConfig.setOrder(order); pluginConfigService.update(pluginConfig); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:/admin/storage_plugin/list.jhtml"; } }