e.g.

class TestAction
{
    @Getter @Setter
    Boolean enabled;// null for both
}

HTML

<input type='radio' name="enabled" value='true'> enabled
<input type='radio' name="enabled" value='false'> disabled
<input type='radio' name="enabled" value='null'> both
<!-- value=null will convert to false -->

How can I pass null for Boolean ?

UPDATE

Answer is impossible. I use another way below.

有帮助吗?

解决方案

My way to around this.

@Data // Generate all setter and getter.
public class UserSearchCondition implements ISearchCondition
{
    private String enabled = null;

    public Boolean isEnabled()
    {
        if (Strings.isNullOrEmpty(enabled) || enabled.toLowerCase().equals("null"))
            return null;
        return Boolean.valueOf(enabled);
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top