www.pudn.com > struts2.rar > JsonPluginAction.java, change:2009-08-21,size:1900b


package com.ajax.action; 
 
import java.util.ArrayList; 
import java.util.List; 
 
import com.googlecode.jsonplugin.annotations.JSON; 
import com.opensymphony.xwork2.ActionSupport; 
 
public class JsonPluginAction extends ActionSupport { 
	 
	private static final long serialVersionUID = -6784977600668791997L; 
	    
	   private int bookId; 
	   private String title; 
	   private double price; 
	   private List<String> comments;     
	   private transient String secret1;//带有transient修饰符与没有Getter方法的字段(field)都不会被串行化为JSON 
	   private String secret2;//带有transient修饰符与没有Getter方法的字段(field)都不会被串行化为JSON 
	    
	   //@JSON的JAVA注释(Annotation),我们可以改变JSON结果的属性名称 
	   @JSON(name="ISBN") 
	   public int getBookId() { 
	       return bookId; 
	   } 
 
	   public void setBookId(int bookId) { 
	       this.bookId = bookId; 
	   } 
 
	   public List<String> getComments() { 
	       return comments; 
	   } 
 
	   public void setComments(List<String> comments) { 
	       this.comments = comments; 
	   } 
 
	   public double getPrice() { 
	       return price; 
	   } 
 
	   public void setPrice(double price) { 
	       this.price = price; 
	   } 
 
	   public String getTitle() { 
	       return title; 
	   } 
	    
	   public void setTitle(String title) { 
	       this.title = title; 
	   } 
 
	   @Override 
	   public String execute() { 
	       bookId = 15645912; 
	       title = "Max On Java"; 
	       price = 0.9999d; 
	       comments = new ArrayList<String>(3); 
	       comments.add("It's no bad!"); 
	       comments.add("WOW!"); 
	       comments.add("No comment!"); 
	       secret1 = "You can't see me!";//带有transient修饰符与没有Getter方法的字段(field)都不会被串行化为JSON 
	       secret2 = "I am invisible!";//带有transient修饰符与没有Getter方法的字段(field)都不会被串行化为JSON 
	       return SUCCESS; 
	   } 
	}