论坛首页 入门技术论坛

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

浏览 2109 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-06-27  
项目使用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的。
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics