欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

我项目中struts2的用法,请大家指正。 SpringAppfuseBeanXML 

程序员文章站 2024-02-20 22:46:52
...
项目使用Struts2+spring2.0+hibernate3.2

BookAction.java
public class BookAction extends BaseAction{

    private BookManager bookManager;
    private Book book;
    private List books;      
    private Integer id;
    private Boolean isNew;  

    public void setBookManager(BookManager bookManager) {
this.bookManager = bookManager;
}      
   
    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getId() {
        return id;
    }
    public void setIsNew(Boolean isNew) {
        this.isNew = isNew;
    }
 
    public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public List getBooks(){
    return books;
    }
public String delete() throws IOException {
        String[] ids = getRequest().getParameterValues("itemlist");
     
        int success = 0;
        if (ids != null) {
            for (int i = 0; i < ids.length; i++) {
                String id = ids[i];
                try {
                    bookManager.removeBook(bookw Integer(id));
                    success++;
                }
                catch (DataIntegrityViolationException e) {
                }
            }
            saveMessage("成功删除" + success + "条纪录!");
        }
        return SUCCESS;
    }

    public String edit() throws IOException {
     
   
    if (isNew == false && id != null) {       
            book = bookManager.getBook(id);
        }else {
            book = new Book();
        }
       
        return SUCCESS;
    }    

    public String save() throws Exception {
        try{
        bookManager.saveBook(book);
        }catch(Exception e){        
        return INPUT;
        }
            
        return SUCCESS;
    }

    public String list() {
    books = bookManager.getAllBook();    
        return SUCCESS;
    }    
}

action在spring中配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName" default-lazy-init="true">
    <bean id="bookAction" class="com.meetyou930.action.BookAction"/>    
</beans>

有个问题是:
1、如果我在这个配置中加上,singleton="false",那么当我修改后保存的时候,将会新增一条记录,而不是修改。而且struts2的服务器端校验也不好使。
2、使用默认的singleton="true",多人操作的时候是否会有问题?
另外,哪位有写的比较好的BaseAction类希望能共享一下,我现在用的是appfuse的。