Java tutorial
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.glaf.mail.web.springmvc; import java.util.*; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import com.glaf.core.config.*; import com.glaf.core.util.*; import com.glaf.mail.domain.*; import com.glaf.mail.service.*; @Controller("/mail/mailStorage") @RequestMapping("/mail/mailStorage") public class MailStorageController { protected final transient Log logger = LogFactory.getLog(MailStorageController.class); protected IMailStorageService mailStorageService; public MailStorageController() { } @RequestMapping("/edit") public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); request.removeAttribute("canSubmit"); Map<String, Object> params = RequestUtils.getParameterMap(request); String rowId = ParamUtils.getString(params, "storageId"); MailStorage mailStorage = null; if (StringUtils.isNotEmpty(rowId)) { mailStorage = mailStorageService.getMailStorage(rowId); request.setAttribute("mailStorage", mailStorage); } String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } String x_view = CustomProperties.getString("mailStorage.edit"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/mail/mailStorage/edit", modelMap); } @RequestMapping public ModelAndView list(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); String x_query = request.getParameter("x_query"); if (StringUtils.equals(x_query, "true")) { Map<String, Object> paramMap = RequestUtils.getParameterMap(request); String x_complex_query = JsonUtils.encode(paramMap); x_complex_query = RequestUtils.encodeString(x_complex_query); request.setAttribute("x_complex_query", x_complex_query); } else { request.setAttribute("x_complex_query", ""); } String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } String x_view = CustomProperties.getString("mailStorage.list"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/mail/mailStorage/list", modelMap); } @RequestMapping("/query") public ModelAndView query(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } String x_view = CustomProperties.getString("mailStorage.query"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/mail/mailStorage/query", modelMap); } @javax.annotation.Resource public void setMailStorageService(IMailStorageService mailStorageService) { this.mailStorageService = mailStorageService; } @RequestMapping("/view") public ModelAndView view(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); Map<String, Object> params = RequestUtils.getParameterMap(request); String rowId = ParamUtils.getString(params, "rowId"); MailStorage mailStorage = null; if (StringUtils.isNotEmpty(rowId)) { mailStorage = mailStorageService.getMailStorage(rowId); request.setAttribute("mailStorage", mailStorage); Map<String, Object> dataMap = Tools.getDataMap(mailStorage); String x_json = JsonUtils.encode(dataMap); x_json = RequestUtils.encodeString(x_json); request.setAttribute("x_json", x_json); } String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view); } String x_view = CustomProperties.getString("mailStorage.view"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view); } return new ModelAndView("/modules/mail/mailStorage/view"); } }