?? addnewsaction.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 + -