Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gwt 首选使用record.getAttribute还是record.GetAttributesType?_Gwt_Smartgwt - Fatal编程技术网

Gwt 首选使用record.getAttribute还是record.GetAttributesType?

Gwt 首选使用record.getAttribute还是record.GetAttributesType?,gwt,smartgwt,Gwt,Smartgwt,我正在使用MySQL开发环境,但我的应用程序可能位于暂存环境的SQLServer上 在我的数据库中,布尔(boolean)被记录为VARCHAR,整数(int)也被记录为VARCHAR 方法record.GetAttributesType是否合适/确定要使用?或者使用类似于typemyvar=newtype(record.getAttribute(“COLUNM_NAME”))的东西更好吗 在解决方案1和2之间使用什么更好 例1: boolean mybool=record.getAttrib

我正在使用MySQL开发环境,但我的应用程序可能位于暂存环境的SQLServer上

在我的数据库中,布尔(
boolean
)被记录为VARCHAR,整数(
int
)也被记录为VARCHAR

方法record.GetAttributesType是否合适/确定要使用?或者使用类似于
typemyvar=newtype(record.getAttribute(“COLUNM_NAME”))
的东西更好吗

在解决方案1和2之间使用什么更好

例1:

boolean mybool=record.getAttributeAsBoolean(“COLUNM_NAME”);//解决方案1
boolean mybool=new boolean(record.getAttribute(“COLUNM_NAME”);//解决方案2
例2:

int myint=record.getAttributeAsInt(“COLUNM_NAME”);//解决方案1
int myint=new integer(record.getAttribute(“COLUNM_NAME”);//解决方案2

对我来说,
VARCHAR
可能比
java.lang.Boolean
java.lang.Integer
更接近
java.lang.String
。因此,我认为在这些例子中,“解决方案2”更为确定。

这取决于具体情况。如果您完全确定该属性的值属于所需的类型,则应使用GetAttributesType()。您的数据源(如果您使用的是ds.xml)是如何定义该字段的?它可能会被smartGWT隐式转换

看起来您的值存储为字符串(例如:record.setAttribute(“COLUMN_NAME”,“12345”),调用record.getAttributeAsInt(“COLUMN_NAME”)可能会失败,并出现类型异常。在这种情况下,您唯一能做的就是实例化整型或静态转换整型:Integer.parseInt(recrod.getAttribute())


GetAttributesType很方便,我尽可能多地使用它,但您必须确保设置时的值是正确的类型。

确切地说,对于我来说,
VARCHAR
更像是
java.lang.String