简体   繁体   English

Grails命令对象绑定数字失败

[英]Grails Command object failed to bind numbers

Hello everyone, I am a newbie to grails. 大家好,我是个新手。 I am passing field values from gsp to controller via command object. 我通过命令对象将字段值从gsp传递到控制器。 There is one field called mobile number on my gsp page.But when i am going to access it via command object,it gives me error as typeMismatch ie it doesn't convert value like 98xxxxxxxx from string to integer.In my command object,i have mentioned it as integer as 我的gsp页面上有一个称为移动电话号码的字段。但是当我要通过命令对象访问它时,它给我报错为typeMismatch,即它没有将98xxxxxxxx之类的值从字符串转换为整数。在我的命令对象中,i提到它作为整数

 Integer mobile;

My code on gsp is : 我在gsp上的代码是:

 <label for="mobile">Mobile</label>
 <input type="text" value="${cmd?.mobile}" title="" name="mobile" id="mobile" size="30" maxlength="10"/>

where cmd is my command object. cmd是我的命令对象。

And code in controller : 和控制器中的代码:

def addInstitute={InstituteCommand cmd->
   Address address=new Address();
   address.mobile=cmd.mobile;
}

It gives me typeMismatch error.Also when i enter values like 1111111111,it saves it but when i enter actual mobile no. 它给了我typeMismatch错误。另外,当我输入1111111111之类的值时,它会保存它,但是当我输入实际的手机号码时。 it gives me typeMismatch error.What to do with this scenario ? 它给我typeMismatch错误。在这种情况下该怎么办?

Thats because the Integer range of values is from -2147483648 to 2147483647, whereas your mobile number is greater than 9800000000 (10 digits). 那是因为值的整数范围是从-2147483648到2147483647,而您的手机号码大于9800000000(10位数字)。 You are better off storing it as a String 您最好将其存储为字符串

String mobile;

This makes more sense since you will most probably not perform any number operations on the mobile number. 这更有意义,因为您很可能不会在手机号码上执行任何号码操作。 It will also allow you to store non-digit phone codes like +, - 它还将允许您存储非数字电话代码,例如+,-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM