Package com.lgx8.management.action

Source Code of com.lgx8.management.action.NewsController

package com.lgx8.management.action;

import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.lgx8.common.PageArgument;
import com.lgx8.common.PageList;
import com.lgx8.common.servlet.BaseController;
import com.lgx8.common.util.StrUtil;
import com.lgx8.management.dao.INewsDao;
import com.lgx8.management.entities.News;
import com.lgx8.right.entities.RunTimeUser;

/**
* 处理新闻、公告、规则类
* @author chenbutao
*
*/
@Controller
public class NewsController  extends BaseController{
  @Resource(name="newsDao")
  private INewsDao newsDao;
 
  /**
   * 新闻公告规则查询
   * @param request
   * @param response
   * @return
   */
  @RequestMapping("/news/newsPageQuery.do")
  public ModelAndView newsPageQuery(HttpServletRequest request,HttpServletResponse response){
    String title = request.getParameter("title");
    String author = request.getParameter("author");
    String stime = request.getParameter("stime");
    String etime = request.getParameter("etime");
    String type = request.getParameter("type");
    NewsQueryForm queryForm = new NewsQueryForm();
    queryForm.setTitle(title);
    queryForm.setAuthor(author);
    queryForm.setEtime(etime);
    queryForm.setStime(stime);
    queryForm.setType(type);
    PageArgument pageArgment = getPageInfo(request);
    PageList pageList = newsDao.findUserByConditions(queryForm.toHql(), queryForm.getPara(), pageArgment);
    printJSON(response, pageList.toJSON());
    return null;
  }
  /**
   * 删除新闻公告规则
   * @param request
   * @param response
   * @return
   */
  @RequestMapping("/news/newsDel.do")
  public ModelAndView newsDel(HttpServletRequest request,HttpServletResponse response){
    //准备删除新闻公告规则
        String[] newsIds = this.getKeyStoreArray(request);
        if (newsIds.length > 0) {
        for (int i = 0 ; i < newsIds.length ; i++) {
          News news = newsDao.findById(StrUtil.parseInt(newsIds[i]));
          newsDao.delete(news);
        }
      }
    this.clearKeyStore(request);
    return null;
  }
 
  @RequestMapping("/news/forAdd.do")
  public ModelAndView forAdd(HttpServletRequest request,HttpServletResponse response){
    String id = request.getParameter("id");
    String type = request.getParameter("type");
    if (!StrUtil.isNullStr(type)){
      return new ModelAndView("/management/news/modify_news").addObject("type", type);
    }
    if (!StrUtil.isNullStr(id)) {
      News news = newsDao.findById(StrUtil.parseInt(id));
      return new ModelAndView("/management/news/modify_news").addObject("news", news);
    }
    return null;
  }
 
  @RequestMapping("/news/save.do")
  public ModelAndView save(HttpServletRequest request,HttpServletResponse response){
    String type = request.getParameter("type");
    String id = request.getParameter("id");
    String title = request.getParameter("title");
    String content = request.getParameter("content");
    RunTimeUser rtUser = RunTimeUser.getRunTimeUser(request);
    if (!StrUtil.isNullStr(id)) {
      News news = newsDao.findById(StrUtil.parseInt(id));
      news.setTitle(title);
      news.setContent(content);
      newsDao.update(news);
    } else {
      News news = new News();
      news.setTime(new Date());
      news.setAuthor(rtUser.getUsername());
      news.setContent(content);
      news.setTitle(title);
      news.setType(StrUtil.parseInt(type));
      newsDao.save(news);
    }
    String returnPage = "";
    if ("1".equals(type)) {
      returnPage = "../page/management/news/list_news.jsp";
    } else if ("2".equals(type)) {
      returnPage = "../page/management/news/list_notice.jsp";
    } else {
      returnPage = "../page/management/news/list_rule.jsp";
    }
    return new ModelAndView(new RedirectView(returnPage));
  }
}
TOP

Related Classes of com.lgx8.management.action.NewsController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.