Part1 Learn for groovy in code
println("hello groovy");
println "hello groovy you can simplify the sentence"
def i = 18
println i
def s = "XiMing"
println s
def list = ['a', 'b']
list << 'c'
println list.get(2)
def map = ['key1': 'value1', 'key2': 'value2']
map.key3 = 'value3'
println map.get("key3")
def b1 = {
println "hello b1"
}
def method1(Closure closure) {
closure()
}
method1(b1)
def b2 = {
v -> {
println "hello ${v}"
}
}
def method2(Closure closure) {
closure("itHeima")
}
method2 (b2)
Part 2 Lean for gradle in config file:build.gradle
plugins {
id 'groovy'
}
group = 'org.itheima'
version = '1.0-SNAPSHOT'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation 'org.apache.groovy:groovy:4.0.14'
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
implementation group: 'org.springframework', name: 'spring-context', version: '6.0.11'
}
test {
useJUnitPlatform()
}