此代码是在action里的,queryName和queryValue的值是从jsp传进来的protected String queryName;
protected String queryValue;
public String getQueryName() {
return queryName;
}
public void setQueryName(String queryName) {
this.queryName = queryName;
}
public String getQueryValue() {
return queryValue;
}
public void setQueryValue(String queryValue) {
this.queryValue = queryValue;
}public String save()throws Exception{
     if(this.getBooks().getBookPrice().equals("")){
     this.getBooks().setBookPrice("0.0");
     }
     String id = this.getBooks().getBookId();
     Books books = bookService.getBook(id);
     if(books==null){
     bookService.addBook(this.getBooks());
     }else{
     bookService.updateBook(this.getBooks());
     }
     this.setQueryName(this.getQueryName());
     this.setQueryValue(this.queryValue);

    
     return SUCCESS;
    }红色部分是不是多余的呀??this.getQueryName()出来的值再自己setQueryName(this.getQueryName())回去不是多余的吗?有什么不一样的?

解决方案 »

  1.   

    最后哪句写错了,应该是this.setQueryValue(this.getQueryValue());
      

  2.   

    多不多余,要看你的用途。每一条语句都会对程序有影响。如果你是从jsp传到action,再传到jsp,就是多余的,如果在action中想修改由jsp传入的值,就不多余。看你的程序好象没修改两个属性值,应该是不必要的。在struts 2中所有的值都放到valuestack或其他贯穿整个请求域的对象中。