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/mailAccount") @RequestMapping("/mail/mailAccount") public class MailAccountController { protected final transient Log logger = LogFactory.getLog(MailAccountController.class); protected IMailAccountService mailAccountService; public MailAccountController() { } @javax.annotation.Resource public void setMailAccountService(IMailAccountService mailAccountService) { this.mailAccountService = mailAccountService; } @RequestMapping("/edit") public ModelAndView edit(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); Map<String, Object> params = RequestUtils.getParameterMap(request); String rowId = ParamUtils.getString(params, "accountId"); MailAccount mailAccount = null; if (StringUtils.isNotEmpty(rowId)) { mailAccount = mailAccountService.getMailAccount(rowId); if (StringUtils.equals(RequestUtils.getActorId(request), mailAccount.getCreateBy())) { request.setAttribute("mailAccount", mailAccount); } } String view = request.getParameter("view"); if (StringUtils.isNotEmpty(view)) { return new ModelAndView(view, modelMap); } String x_view = CustomProperties.getString("mailAccount.edit"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/mail/mailAccount/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("mailAccount.list"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/mail/mailAccount/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("mailAccount.query"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/mail/mailAccount/query", modelMap); } @RequestMapping("/view") public ModelAndView view(HttpServletRequest request, ModelMap modelMap) { RequestUtils.setRequestParameterToAttribute(request); Map<String, Object> params = RequestUtils.getParameterMap(request); String rowId = ParamUtils.getString(params, "accountId"); MailAccount mailAccount = null; if (StringUtils.isNotEmpty(rowId)) { mailAccount = mailAccountService.getMailAccount(rowId); request.setAttribute("mailAccount", mailAccount); Map<String, Object> dataMap = Tools.getDataMap(mailAccount); 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("mailAccount.view"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view); } return new ModelAndView("/modules/mail/mailAccount/view"); } }