如何在java中编写nullable int? [英] How to write nullable int in java?
本文介绍了如何在java中编写nullable int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将Web表单转换为Java模型。
I want to convert a web form to a model in Java.
在C#中我可以这样写:
In C# I can write this:
<input name="id" value="" type="text"/>
public class Test
{
public int? Id{get;set;}
}
id
可以为null。
但是在Java中使用struts2时会引发异常:
But in Java when using struts2 it throws an exception:
Method "setId" failed
那么如何写这个案例在Java?
So how to write this case in Java?
推荐答案
你可以使用Integer这是一个可以为空的。
You can use Integer which is a class and is nullable.
这篇关于如何在java中编写nullable int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文