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
@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) } }
|