⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addnewsaction.java

📁 Spring2.0宝典
💻 JAVA
字号:
package org.yeeku.webapp.action;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.yeeku.model.Category;
import org.yeeku.model.News;
import org.yeeku.model.User;
import org.yeeku.service.CategoryManager;
import org.yeeku.service.NewsManager;
import org.yeeku.service.UserManager;
import org.yeeku.webapp.util.AppConstants;

import com.opensymphony.xwork.ActionContext;

public class AddNewsAction extends BaseAction {
	private String categoryId;
	
	private String title;

	private String content;

	public String getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String execute() throws Exception {
		log.debug("AddNewsAction executed.");
		//FacadeManager mgr = (FacadeManager) getBean("facadeManager");
		CategoryManager cmgr = (CategoryManager)getBean("categoryManager");
		UserManager umgr = (UserManager) getBean("userManager");
		NewsManager nmgr = (NewsManager) getBean("newsManager");
		Category category = cmgr.getCategory(categoryId);		
		String username = (String) ActionContext.getContext().getSession().get(
				AppConstants.LOGIN_USER);
		User poster = umgr.getUser(username);
		News news = new News();
		news.setCategory(category);
		news.setPoster(poster);
		news.setTitle(title);
		news.setContent(content);
		news.setPostDate(new Date());
		news.setLastModifyDate(new Date());
		nmgr.saveNews(news);
		Map params = new HashMap();
		params.put("categoryId",categoryId);
		ActionContext.getContext().setParameters(params);
		return SUCCESS;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -