Java tutorial
/* * Project: admin-parent * * File Created at 2014-04-01 * * Copyright 2012 Greenline.com Corporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * Greenline Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Greenline.com. */ package com.greenline.hrs.admin.web.war.user; import com.greenline.hrs.admin.user.service.UserInfoService; import com.greenline.hrs.admin.user.vo.UserNormalInfo; import com.greenline.hrs.admin.web.base.common.cons.WebResponseConst; import com.greenline.hrs.admin.web.base.user.cons.UserResponseConst; import com.greenline.hrs.admin.web.base.user.cons.UserViewConst; import com.greenline.hrs.admin.web.base.util.JSONResponseUtil; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * @author July * @Type RedisConnConfigController * @Desc ?Controller * @date 2014-04-01 * @Version V1.0 */ @Controller @RequestMapping("/user/info") public class UserInfoController { private static final Log LOG = LogFactory.getLog(UserInfoController.class); /** * ? */ @Autowired private UserInfoService userInfoService; /** * ? * * @return */ @RequestMapping(value = "add", method = RequestMethod.GET) public String addUserPage() { return UserViewConst.USER_INFO_EDIT_VIEW; } /** * ? * * @param userNormalInfo ? * @param modelMap View?Map * @return ??? */ @RequestMapping(value = "edit", method = RequestMethod.POST) public String addUser(@ModelAttribute UserNormalInfo userNormalInfo, ModelMap modelMap) { modelMap.remove(WebResponseConst.ERROR_MESSAGES); modelMap.remove(WebResponseConst.INFO_MESSAGES); //????? List<String> infoMessages = null; //????? List<String> errorMessages = null; Date now = new Date(); userNormalInfo.setCreateTime(now); userNormalInfo.setUpdateTime(now); Long uid = userInfoService.addUser(userNormalInfo); //UID, if (uid != null) { infoMessages = new ArrayList<String>(); infoMessages.add(UserResponseConst.ADD_USER_SUCCESS); modelMap.put(WebResponseConst.INFO_MESSAGES, infoMessages); } else {//UID,? errorMessages = new ArrayList<String>(); errorMessages.add(UserResponseConst.ADD_USER_FAIL); modelMap.put(WebResponseConst.ERROR_MESSAGES, errorMessages); } modelMap.put("userInfo", userNormalInfo); return UserViewConst.USER_INFO_EDIT_VIEW; } /** * ???,? * * @param uid ID * @param modelMap View?Map * @return , ??, ?? */ @RequestMapping(value = "edit/{uid:\\d+}", method = RequestMethod.GET) public String editUserNormalInfoPage(@PathVariable long uid, ModelMap modelMap) { if (uid > 0) { UserNormalInfo userNormalInfo = userInfoService.getUserNomalInfo(uid); if (userNormalInfo != null) { modelMap.put("userInfo", userNormalInfo); } } return UserViewConst.USER_INFO_EDIT_VIEW; } /** * * * @param pageNo ?,1 * @param modelMap * @return */ @RequestMapping(value = "list/{pageNo:\\d+}", method = RequestMethod.GET) public String listUserNormalInfoPage(@PathVariable int pageNo, ModelMap modelMap) { int offset = pageNo < 1 ? 0 : (pageNo - 1) * UserResponseConst.USER_LIST_SIZE; modelMap.put(UserResponseConst.USER_INFO_LIST, userInfoService.getUserInfoList(offset, UserResponseConst.USER_LIST_SIZE)); return UserViewConst.USER_INFO_LIST_VIEW; } /** * * * @param map ?,id. * @return JSON?, ???. */ @RequestMapping(value = "/del", method = RequestMethod.POST, produces = { "application/json;charset=UTF-8" }) @ResponseBody public Object deleteUser(@RequestBody MultiValueMap<String, String> map) { String uidStr = map.getFirst("uid"); //id??, if (!StringUtils.isNumeric(uidStr)) { LOG.info(UserResponseConst.ADD_USER_FAIL + uidStr); return JSONResponseUtil.failObject(UserResponseConst.DEL_USER_FAIL); } userInfoService.delUserNomalInfo(Long.valueOf(uidStr)); LOG.info(JSONResponseUtil.successString(UserResponseConst.DEL_USER_SUCCESS)); return JSONResponseUtil.successObject(UserResponseConst.DEL_USER_SUCCESS); } }