Spring+DWR 配置

先写一个有验证用户名和邮箱的两个方法customerDWR类:其中customerService是用户业务层,Service层与DAO层这里省略

package com.fzwx.been.dwr;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.fzwx.model.Customer;
import com.fzwx.service.CustomerService;
/**
 * 前台用户注册表单验证DWR
 * @author Jason 2009.9.25
 */
public class CustomerDWR {
	private CustomerService customerService;

	public CustomerService  getCustomerService () {
		return customerService;
	}
	public void setCustomerService(CustomerService customerService) {
		this.customerService = customerService;
	}
	
	/**
	 * 验证用户名的方法
	 * 如果用户名为空,则返回nullfalse;
	 * 如果数据库里不存在该用户名并且用户名格式为(英文字母、数字、下划线)则返回bothtrue;
	 * 如果数据库里存在该用户名并且用户名格式为(英文字母、数字、下划线)则返回DBfalse;
	 * 如果数据库里不存在该用户名并且用户名格式不为(英文字母、数字、下划线)则返回formatfalse;
	 * 如果数据库里存在该用户名并且用户名格式不为(英文字母、数字、下划线)则返回bothfalse;
	 * @param String customerName
	 * @return string
	 */
	public String validateCustomerName(String customerName){		
		Customer customer=customerService.findCoustomerByName(customerName.toLowerCase());
		String reg="^[a-zA-Z0-9_]{1,20}$";
	    Pattern   p   =   Pattern.compile(reg);  
	    Matcher   m   =   p.matcher(customerName);
		if("".equals(customerName))
			return "nullfalse";
		else{
			if(customer==null&&m.matches())
				return "bothtrue"; 
			if(customer==null&&!m.matches())
				return "formatfalse"; 
			if(customer!=null&&m.matches())
				return "DBfalse"; 
		}
		return "bothfalse";

	}
	
	/**
	 * 验证数据库里该邮箱是否存在的方法
	 * 如果数据库里已经存在该邮箱,则放回DBfalse
	 * 如果数据库里不存在该邮箱,则返回DBtrue;
	 * @param String email
	 * @return string
	 */
	public String validateCustomerEmail(String email){
		Customer customer=customerService.findCoustomerByEmail(email.toLowerCase());
		if(customer==null){
			return "DBtrue";
		}
		else{
			return "DBfalse";
		}
		
	}
}

 

把customerDWR这个类加入Spring 容器,在Spring 配置文件 applicationContext_Control.xml中加入以下代码:

<!-- 用户DWR -->
  <bean id="customerDWR" class="com.fzwx.been.dwr.CustomerDWR">
    <property name="customerService">
      <ref bean="customerService" />
    </property>
  </bean>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值