男人创造作品,而女人创造男人——罗曼·罗兰

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.ruben.simpleboot

import org.junit.jupiter.api.Test
import org.springframework.beans.factory.BeanFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.expression.BeanFactoryResolver
import org.springframework.expression.spel.standard.SpelExpressionParser
import org.springframework.expression.spel.support.StandardEvaluationContext


/**
* @author VampireAchao
* @since 2022/10/18 17:08
*/
@SpringBootTest
class SPELTest {


@Test
fun test(@Autowired beanFactory: BeanFactory) {
val expression = SpelExpressionParser()
.parseExpression("1+(@userInfoMapper.limit(20L).size()+20)*4")
val value = expression.getValue(StandardEvaluationContext().apply {
setBeanResolver(BeanFactoryResolver(beanFactory))
})
print(value)
}
}