gpt4 book ai didi

java - 在 ModelDriven 中获取空值 NULL

转载 作者:行者123 更新时间:2023-12-01 04:29:25 26 4
gpt4 key购买 nike

ModelDriven 对于具有空值的 params 返回 NULL

bean :

public class MyBean
{
private String userName;
public void setUserName(String userName)
{
this.userName = userName;
}
public String getUserName()
{
return userName;
}
}

类别:

public class MyAction extends ActionSupport implements ModelDriven<MyBean>
{
MyBean myBean = new MyBean();
public String execute()
{
System.out.println(myBean.getUserName());//getting null here
return "SUCCESS";
}
}

请求:

/home/MyAction.do?userName=&pass=

听说我为 userName 参数传递了空值,但在实际操作中我得到了 null 值。

如何在ModelDriven中获取精确值?

最佳答案

当您的 bean 属性包含 null 值时,它会将该值保留在 OGNL 表达式和 value 标记中。您始终可以使用 OGNL 表达式来计算 null 值。例如

<s:if test="userName == null">
<s:property value="username"/>
</s:if>

如果您想将 null 值作为参数传递,那么您应该使用 null 字符串。

/home/MyAction.do?userName="null"&pass="null"

关于java - 在 ModelDriven 中获取空值 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18130488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com