Java tutorial
/** * Copyright © 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); */ package com.hongqiang.shop.modules.cms.web.front; import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; 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.servlet.mvc.support.RedirectAttributes; import com.hongqiang.shop.common.config.Global; import com.hongqiang.shop.common.persistence.Page; import com.hongqiang.shop.common.servlet.ValidateCodeServlet; import com.hongqiang.shop.common.web.BaseController; import com.hongqiang.shop.modules.cms.entity.Guestbook; import com.hongqiang.shop.modules.cms.entity.Site; import com.hongqiang.shop.modules.cms.service.GuestbookService; import com.hongqiang.shop.modules.cms.utils.CmsUtils; /** * ?Controller * @author ThinkGem * @version 2013-3-15 */ @Controller @RequestMapping(value = "${frontPath}") public class FrontGuestbookController extends BaseController { @Autowired private GuestbookService guestbookService; /** * ? */ @RequestMapping(value = "guestbook", method = RequestMethod.GET) public String guestbook(@RequestParam(required = false, defaultValue = "1") Integer pageNo, @RequestParam(required = false, defaultValue = "30") Integer pageSize, Model model) { Site site = CmsUtils.getSite(Site.defaultSiteId()); model.addAttribute("site", site); Page<Guestbook> page = new Page<Guestbook>(pageNo, pageSize); Guestbook guestbook = new Guestbook(); guestbook.setDelFlag(Guestbook.DEL_FLAG_NORMAL); page = guestbookService.find(page, guestbook); model.addAttribute("page", page); return "modules/cms/front/themes/" + site.getTheme() + "/frontGuestbook"; } /** * ?-?? */ @RequestMapping(value = "guestbook", method = RequestMethod.POST) public String guestbookSave(Guestbook guestbook, String validateCode, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) { if (StringUtils.isNotBlank(validateCode)) { if (ValidateCodeServlet.validate(request, validateCode)) { guestbook.setIp(request.getRemoteAddr()); guestbook.setCreateDate(new Date()); guestbook.setDelFlag(Guestbook.DEL_FLAG_AUDIT); guestbookService.save(guestbook); addMessage(redirectAttributes, "????"); } else { addMessage(redirectAttributes, "???"); } } else { addMessage(redirectAttributes, "???"); } return "redirect:" + Global.getFrontPath() + "/guestbook"; } }