我正在使用grails框架,并且在服务groovy文件中有这些行代码。我在这段代码中看到,它看起来像map已经实现但是我不明白它如何工作而不将它分配给这个文件中的任何变量。
class ApprovalHeaderLEADEDService extends ApprovalHeaderService {
def generateTable(ApprovalHeader ah,BondingDiagram bd){
def waferMountOrientation= findApprovalHeaderKitName(ah,bd,"WaferMountOrientation");
def sawForModels = findApprovalHeaderKitName(ah,bd,"SawForModels");
def sawBladeType1= findApprovalHeaderKitName(ah,bd,"SawBladeType1");
[
waferMountOrientation:waferMountOrientation,
sawForModels:sawForModels,
sawBladeType1:sawBladeType1
]
}
我希望地图看起来像这样
def map = [waferMountOrientation:waferMountOrientation, sawForModels:sawForModels, sawBladeType1:sawBladeType1]
有人可以向我解释这是如何运作的,或者建议我在哪里可以阅读有关这种地图案例的内容?
答案 0 :(得分:6)
答案 1 :(得分:3)
此:
def generateTable(ApprovalHeader ah,BondingDiagram bd){
def waferMountOrientation= findApprovalHeaderKitName(ah,bd,"WaferMountOrientation");
def sawForModels = findApprovalHeaderKitName(ah,bd,"SawForModels");
def sawBladeType1= findApprovalHeaderKitName(ah,bd,"SawBladeType1");
[
waferMountOrientation:waferMountOrientation,
sawForModels:sawForModels,
sawBladeType1:sawBladeType1
]
}
与此相同:
def generateTable(ApprovalHeader ah,BondingDiagram bd){
def waferMountOrientation= findApprovalHeaderKitName(ah,bd,"WaferMountOrientation");
def sawForModels = findApprovalHeaderKitName(ah,bd,"SawForModels");
def sawBladeType1= findApprovalHeaderKitName(ah,bd,"SawBladeType1");
def someMap = [
waferMountOrientation:waferMountOrientation,
sawForModels:sawForModels,
sawBladeType1:sawBladeType1
]
return someMap
}
一个更简单的示例演示相同的事情(以下所有方法的行为方式相同):
def someMethod() {
42
}
def someMethod() {
return 42
}
def someMethod() {
def value = 42
value
}
def someMethod() {
def value = 42
return value
}