package com.xlj.popedom.action;
import java.util.List;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.RequestAware;
import com.opensymphony.xwork2.ActionSupport;
import com.xlj.popedom.model.Books;
import com.xlj.popedom.model.P_user;
import com.xlj.popedom.serviceInterface.IBookService;
public class BookAction extends ActionSupport implements RequestAware{
private Map<String,Object> request;
private IBookService bookService;
private Books book;
private String type;
public Map<String, Object> getRequest() {
return request;
}
public void setRequest(Map<String, Object> request) {
this.request = request;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public IBookService getBookService() {
return bookService;
}
public void setBookService(IBookService bookService) {
this.bookService = bookService;
}
public Books getBook() {
return book;
}
public void setBook(Books book) {
this.book = book;
}
public String checkType()throws Exception{
Integer id = (Integer) ServletActionContext.getRequest().getSession().getAttribute("user_id");
String powername = this.bookService.checkAdd(id);
String[] s = powername.split(", ");
for(int i=0;i<s.length;i++){
if(type.equals("c")&&type.equals(s[i])){
return "add";
}if(type.equals("d")&&type.equals(s[i])){
return "delete";
}if(type.equals("r")&&type.equals(s[i])){
System.out.println(1111111);
return "reveal";
}if(type.equals("u")&&type.equals(s[i])){
return "update";
}
}
return INPUT;
}
public String addBook()throws Exception{
book.setBook_name(book.getBook_name());
Integer id = (Integer) ServletActionContext.getRequest().getSession().getAttribute("user_id");
P_user pu = new P_user();
pu.setUser_id(id);
book.setP_user(pu);
this.bookService.save(book);
return SUCCESS;
}
public String showBook()throws Exception{
List list = this.bookService.getAllBook();
request.put("listBook", list);
return SUCCESS;
}
public String findById()throws Exception{
Integer id = (Integer) ServletActionContext.getRequest().getSession().getAttribute("user_id");
String powername = this.bookService.checkAdd(id);
String[] s = powername.split(", ");
for(int i=0;i<s.length;i++){
if(type.equals("u")&&type.equals(s[i])){
Books bk = this.bookService.findByid(book.getBook_id());
request.put("listBook", bk);
return SUCCESS;
}
}
return INPUT;
}
public String deleteBook()throws Exception{
Integer id = (Integer) ServletActionContext.getRequest().getSession().getAttribute("user_id");
String powername = this.bookService.checkAdd(id);
String[] s = powername.split(", ");
for(int i=0;i<s.length;i++){
if(type.equals("d")&&type.equals(s[i])){
Books bk = this.bookService.findByid(book.getBook_id());
this.bookService.delete(bk);
return SUCCESS;
}
}
return INPUT;
}
public String updateBook()throws Exception{
Books bk = this.bookService.findByid(book.getBook_id());
bk.setBook_id(book.getBook_id());
bk.setBook_name(book.getBook_name());
this.bookService.update(bk);
return SUCCESS;
}
}
最近下载更多
ClariSDDDD LV6
2018年12月24日
xiaomiao520 LV12
2018年11月6日
林东东 LV1
2018年10月17日
liuhongwei_5201314 LV9
2018年9月3日
tulongjian LV1
2018年6月17日
Rommel LV27
2018年5月17日
2309094456 LV12
2018年4月17日
gxpcwm LV22
2018年4月14日
kevin520 LV11
2017年7月13日
once_彭少 LV3
2017年4月19日

最近浏览