以下是名为Person的Entity
:
@Entity
@Table(
name = "PERSON"
)
public class Person {
//other fields etc
@Column(
name = "PAID_IN_FULL",
nullable = false
)
private String paidInFull;
public void setPaidInFull(boolean paidInFull) {
this.paidInFull = paidInFull?"Y":"N";
}
}
如果要执行以下操作,请使用上面的设置器:
person.setPaidInFull(true);
将其设置为什么字符串值,它是
"Y"
还是"N"
? 最佳答案
paidInFull?"Y":"N";
如果说:
if (paidInFull)
return "Y";
else
return "N";
所以如果你要做
person.setPaidInFull(true);
this.paidInFull
将为“ Y”。这是一个完整的示例:
package nl.testing.startingpoint;
public class Main {
private static String paidInFull;
public static void main(String args[])
{
setPaidInFull(true);
System.out.println(paidInFull);
}
public static void setPaidInFull(boolean paidInFull) {
Main.paidInFull = (paidInFull) ? "Y" : "N";
}
}