⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addfriendinfoaction.java

📁 SSH框架整合... 不错的源码
💻 JAVA
字号:
package com.lideedu.huang.addressBook.struts.action;

import java.lang.reflect.InvocationTargetException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;

import com.lideedu.huang.addressBook.business.IFriendService;
import com.lideedu.huang.addressBook.pojos.Friend;
import com.lideedu.huang.addressBook.struts.form.FriendForm;

public class AddFriendInfoAction extends DispatchAction {

	// fileds
	IFriendService friendService;
	Friend friend;

	// 增加朋友信息
	public ActionForward addFriendInfo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IllegalAccessException, InvocationTargetException {

		ActionMessages messages = new ActionMessages();
		FriendForm friendForm = (FriendForm) form;
		
		//通讯录中是否已有此号码
		boolean isExisted = friendService.checkPhone(friendForm.getPhone());

		if (isExisted) {
			messages.add("phoneIsExisted", new ActionMessage(
					"phoneIsExisted"));
			saveErrors(request, messages);
			return new ActionForward(mapping.getInput());
		}else{
			BeanUtils.copyProperties(friend, friendForm);
			friendService.regFriend(friend);
			messages.add("addFriendInfoSuccess", new ActionMessage("addFriendInfoSuccess"));
			saveErrors(request, messages);
			return new ActionForward(mapping.getInput());
		}
	}

	// getter and setter
	public IFriendService getFriendService() {
		return friendService;
	}

	public void setFriendService(IFriendService friendService) {
		this.friendService = friendService;
	}

	public Friend getFriend() {
		return friend;
	}

	public void setFriend(Friend friend) {
		this.friend = friend;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -