Struts2 action中不要将方法以get开头!!!

Struts2 action中不要将方法以get开头

Struts2 action中不要将方法以get开头

Struts2 action中不要将方法以get开头

重要的事情说三遍!

今天调试jquery发送请求到action中我写的三个方法回一次执行。审查代码一点问题都没有

我写的代码如下:

/**
 * 
 */
package com.artpri.artist.action;

import java.util.List;

import com.opensymphony.xwork2.Action;

/**
 * 
 * @author 王校兵
 * @version 1.0, 2016年4月6日
 */
public class GetQueryAlbumPhotoAction extends BaseAction {

	private List photoList;// 照片的查询结果集合
	private String queryTime;// 要查询照片的拍摄时间条件
	private String queryCategory;// 要查询的年代条件
	private String queryTitle;// 要查询的标题条件

	/**
	 * 通过相册分类查询相册照片action方法
	 * @return 页面跳转对应的逻辑代码
	 * */
	public String getPhotoByCategory() {
		System.out.println("getPhotoByCategory-------------------------------" + queryCategory);
		photoList = getAlbumPhotoMangeService().getPhotoByCategory(queryCategory);
		return Action.SUCCESS;
	}

	/**
	 * 通过拍摄时间查询相册照片action方法
	 * @return 页面跳转对应的逻辑代码
	 * */
	public String getPhotoByTime() {
		System.out.println("getPhotoByTime-------------------------------" + queryTime);
		photoList = getAlbumPhotoMangeService().getPhotoByTime(queryTime);
		return Action.SUCCESS;
	}
	
	/**
	 * 通过照片标题查询相册照片action方法
	 * @return 页面跳转对应的逻辑代码
	 * */
	public String getPhotoByTitle() {
		System.out.println("getPhotoByTitle-------------------------------" + queryTitle);
		photoList = getAlbumPhotoMangeService().getPhotoByTitle(queryTitle);
		return Action.SUCCESS;
	}

	public List getPhotoList() {
		return photoList;
	}

	public String getQueryCategory() {
		return queryCategory;
	}

	public String getQueryTime() {
		return queryTime;
	}

	public String getQueryTitle() {
		return queryTitle;
	}

	public void setPhotoList(List photoList) {
		this.photoList = photoList;
	}

	public void setQueryCategory(String queryCategory) {
		this.queryCategory = queryCategory;
	}

	public void setQueryTime(String queryTime) {
		this.queryTime = queryTime;
	}

	public void setQueryTitle(String queryTitle) {
		this.queryTitle = queryTitle;
	}

}

他们会依次执行。因为action中  ajax模式下,调用的action方法不能为get*方式命名,内中机理未知。

于是就把get开头的方法修改了一下,程序就运行正常了,继续找了下原因,最后基本上明白。
 个人认为,出现这个问题的原因是因为,action中属性都是以get set方式设置的,这样strut2才能根据反射进行设置,但是当action结束的时候,
就会调用相应的get方法取值,所以导致get开头的method执行了两次。
所以

Struts2 action中不要将方法以get开头



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值