buffalo 调方法时 参数的类型

一 :客户端 js 的数组  来 映射 服务器端的 Map 对象 :

首先我们服务器端 有一个java方法 :

     /**
     * 输入一个map ,原封不动的输出来
     * 
@param  arg
     * 
@return  Map
     
*/

    
public  Map object(Map arg)  {
              
return  arg;
    }


在客户端我们有 这样的 js 代码 :

< script language = " javascript " >
var buffalo 
=   new  Buffalo(endPoint)

function sendObject() 
{
    var a 
=   {} ;
    a[Buffalo.BOCLASS] 
=   " java.util.Map " ;
    a[
" a " =   " A " ;
    a[
" b " =   true ;
    a[
" c " =   123.4 ;
    var u 
=   {} ;
    u[Buffalo.BOCLASS] 
=   " net.buffalo.demo.simple.User " ;
    u.id 
=   234 ;
    u.name 
=   " <xml here>& " ;
    u.age 
=   17 ;
    u.sex 
=   false ;
    u.memo 
=   " very beautiful " ;
    a[
" u " =  u;
    buffalo.remoteCall(
" simpleService.object " ,[a], function(reply)  {
        alert(
" return user memo: "   +  reply.getResult()[ " u " ].memo);
    }
);
}

</ script >

注意 这 2  句 :

a[Buffalo.BOCLASS]  =   " java.util.Map " ;

u[Buffalo.BOCLASS]  =   " net.buffalo.demo.simple.User " ;


二 : 将表单序列化为一个dto对象

首先我们在服务器端有一个 dto对象

public   class  User  {
    
private int id;
    
private String name;
    
private int age;
    
private boolean sex;
    
private String memo;
    
    
public User() {
    }




}

接下来我们在客户端有下列代码 :

< script language = " javascript " >
var buffalo 
=   new  Buffalo(endPoint);

function doAnotherSubmit() 
{
    var userObj 
= Buffalo.Form.formToBean("form1""net.buffalo.demo.form.User");
    buffalo.remoteCall(
"userService.createUser", [userObj], function(reply){
        $(
"form_infomsg").innerHTML="Form has been submited, username is: " + reply.getResult().username;
    }
)
}

</ script >

注意这2句 :

var userObj  =  Buffalo.Form.formToBean( " form1 " " net.buffalo.demo.form.User " );

form1表单中 有 User类 中属性  同名 的 表单项 , 这样 userObj 就可以作为在客户端 映射 User  的参数了。

另外 :

$( " form_infomsg " )

可以指页面中 :

< div id = " form_infomsg "  style = " color:blue " ></ div >


表示的位置。


三 :数据绑定

  首先 我们在服务器端有 这样一个变量 :

     public   static  List employees()  {
        
if (employees.size() > 0return employees;
        employees.add(
new EmployeeBean("1""Greg""Murray"));
        employees.add(
new EmployeeBean("2""Greg""Murphy"));
        employees.add(
new EmployeeBean("3""George""Murphy"));
        employees.add(
new EmployeeBean("4""George""Murray"));
        employees.add(
new EmployeeBean("5""Peter""Jones"));
        employees.add(
new EmployeeBean("6""Amber""Jones"));
        employees.add(
new EmployeeBean("7""Amy""Jones"));
        employees.add(
new EmployeeBean("8""Bee""Jones"));
        employees.add(
new EmployeeBean("9""Beth""Johnson"));
        employees.add(
new EmployeeBean("10""Cindy""Johnson"));
        employees.add(
new EmployeeBean("11""Cindy""Murphy"));
        employees.add(
new EmployeeBean("12""Duke""Hazerd"));
        
return employees;
    }

在客户端我们有 这样的代码 :

var buffalo  =   new  Buffalo(endPoint);
function doCompletion() 
{
    buffalo.bindReply(
"ajaxService.filterEmployees",[target.value], "names");
}

同时我们在页面中有 :

< TABLE id = " names "  border = " 1 "  jheight = " 0 " >

结果 :



还有一种形式是 :

    buffalo.remoteCall( " simpleService.allLocales " , [], function(reply)  {
        
/**Buffalo.bind("area", reply.getSource());*/
        Buffalo.bind(tableId, reply.getResult());
    }
)

注意这句

Buffalo.bind(tableId, reply.getResult());
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值