1.静态函数
package com.testspringboot2.util;
public class CustomerUtil {
public static int AGE = 20;
public static String getName(String name) {
return "pre_"+name;
}
}
2.配置文件
<insert id="insert3">
insert into customer (name,age,state) values
("${@com.testspringboot2.util.CustomerUtil@getName(name)}",${@com.testspringboot2.util.CustomerUtil@AGE},1)
</insert>
3.测试
@Test
public void test() {
Customer customer=new Customer();
customer.setName("test");
mapper.insert3(customer);
}
4.结果
![]()

本文介绍如何在SpringBoot项目中利用静态函数进行数据预处理,并通过配置文件实现动态插入数据库的操作。展示了CustomerUtil类的静态方法getName和全局变量AGE的使用,以及在MyBatis配置文件中调用这些静态资源的方法。
1424

被折叠的 条评论
为什么被折叠?



