Groovy简写if else运算符(Groovy shorthand if else operator)
我正在尝试在.gsp文件中设置一个变量,并将一个对象从控制器传递给视图。 ' item '在这种情况下是一个对象,名为' sequence '所以我想要做的是将var'action'设置为item.sequence的值,如果item.sequence为null,则将action值设置为字符串“new”。
<g:set var="action" value= "${item.sequence?item.sequence:'new'}"/>
不幸的是,我将item.sequence和“new”的价值融合在一起。 有谁知道我可以如何做这个速记?
I'm trying to set a variable in a .gsp file with an object been passed to the view from the controller. 'item' is an object in this case with an attribute called 'sequence' So what I'm trying to do is set the var 'action' to the value of item.sequence and if item.sequence is null then set action value to the string "new".
<g:set var="action" value= "${item.sequence?item.sequence:'new'}"/>
Unfortunately, I'm getting the value of item.sequence and "new" together. Does anyone know how I can do this shorthand?
原文:https://stackoverflow.com/questions/26935125
最满意答案
这是合法的但是多余的。 这不是更快。 事实上,虽然检查本身速度很快,但维持与指针有效性同步的布尔值会稍微慢一些。 最糟糕的事情是证明布尔值始终同步的维护负担。 一旦它被实现并且被证明是正确的,那只是多余的而且浪费了内存。
It's legit but redundant. It's not faster. Infact, while the check itself is as fast, maintaining the boolean in sync with the validity of the pointer is marginally slower. The worst thing about it is the maintenance burden of proving that the boolean is always in sync. Once it's implemented and proven correct though, it's just redundant and a waste of memory.
相关问答
更多-
电脑二级考试 是考access 还是VPF[2022-06-08]
access -
CGO:你如何使用Golang中的指针来访问C中数组的数据(CGO: How do you use pointers in Golang to access data from an array in C)[2023-08-31]
由于库作者没有为您创建切片头,因此您需要将返回的值转换为unsafe.Pointer ,然后转换为uintptr这将允许您对其执行指针算术以便稍后获取元素在记忆中。 这里有一些示例代码应该在go playground上运行。 package main import ( "fmt" "unsafe" ) func main() { nums := []uint8{1, 2, 3, 4, 5, 6, 7, 8} val := &nums[0] // val is the e ... -
无论是本地化还是数据库格式,在所有情况下,True都不是FALSE,或者不是0。 因此,如果用NOT 0替换True的所有测试,用0替换False的所有测试,那么你就避免了Access关键字的本地化问题(我很惊讶VBA和Jet和Access表达式服务不会仍然可以理解True / False,以及数据库引擎用于存储布尔值的任何约定。 一般来说,您的数据访问层应该为您抽象出来。 ODBC和ADO都会自动执行,因此您可以使用您知道的布尔值,并根据我的经验透明地为您处理。 我仍然对这个问题感到困惑,因为它听起来像是 ...
-
这是合法的但是多余的。 这不是更快。 事实上,虽然检查本身速度很快,但维持与指针有效性同步的布尔值会稍微慢一些。 最糟糕的事情是证明布尔值始终同步的维护负担。 一旦它被实现并且被证明是正确的,那只是多余的而且浪费了内存。 It's legit but redundant. It's not faster. Infact, while the check itself is as fast, maintaining the boolean in sync with the validity of the po ...
-
如何创建一个将字符串转换为布尔值的访问方法(How do you create an access method to convert a string to a boolean)[2022-08-25]
喜欢这个? protected boolean fullTime; public String getFullTimeAsString(){ return Boolean.toString(fullTime); } public void setFullTimeAsString(String fulltimeStr){ fullTime = "true".equalsIgnoreCase(fulltimeStr); } 编辑: private static final String Y ... -
您无法从Menu脚本访问stereo变量,因为stereo是在函数中声明的。 在函数外声明它然后在Awake()函数中初始化它。 您还必须将其public才能访问它。 public GvrViewer MonoOrStereo = new GvrViewer(); public bool stereo; void Awake() { stereo = MonoOrStereo.VRModeEnabled; } public void LoadStereo(bool stereo) { ...
-
可扩展的方式来访问ConcurrentHashMap的每个元素
一次(Scalable way to access every element of ConcurrentHashMap [2023-09-07]exactly once) 我可以尝试从ConcurrentHashMap继承,获取其内部Segment的实例,尝试将它们分组为32个组并分别处理每个组。 这听起来像是一个硬核方法。 硬核确实,但我唯一能看到它会起作用。 toArray()通过枚举来构建数组,因此没有胜利。 我无法相信同步HashSet会更好,除非visit()运行与其他map操作的比率相当高。 使用Segment的问题在于,您必须非常小心您的代码是有弹性的,因为我假设其他线程可能在您访问节点的同时更改表,并且您需要避免不可避免的竞争条件。 确实很精致。 我心中最大的 ... -
您可以获得每个类别的个人总数: SELECT COUNT(*) FROM STUDENTS WHERE HasBamboo 把它们全部加起来,除以 SELECT COUNT(*) FROM STUDENTS 虽然这不是一个很棒的数据库设计......更好的规范化将是: Table Students; fields StudentID, StudentName Table Plants; fields PlantID, PlantName Table OwnedPlants; fields Student ...
-
您可以创建一个简单的类来跟踪用户的状态,通过使用singletone,您可以从应用程序的任何位置访问它。 SGUser.h #import
@interface SGUser : NSObject + (SGUser *) activeUser; @property BOOL loggedIn; @end SGUser.m #import "SGUser.h" @implementation SGUser + (SGUser *) activeUs ...