SET @batch_date = '20230222'; set @partition_name=concat('p',@batch_date); set @stat=concat('alter table tb_bond_price_comparision_reuslt truncate partition ',@partition_name); prepare stmt from @stat; execute stmt; set @stat=concat('alter table tb_trade_blotter_op_sec_liquidity_risk truncate partition ',@partition_name); prepare stmt from @stat; execute stmt; set @stat=concat('alter table tb_bond_price_comparision_trade_blotter_op_sec_mul truncate partition ',@partition_name); prepare stmt from @stat; execute stmt;转换为mybatis的xml文件中执行语句并生成spring boot的service层代码
时间: 2024-02-03 18:11:40 浏览: 128
set /p= 命令使用详解
1. 在mybatis的xml文件中添加以下语句:
```
<update id="truncatePartitions" parameterType="java.util.Map">
SET @batch_date = #{batchDate};
set @partition_name=concat('p',@batch_date);
set @stat=concat('alter table tb_bond_price_comparision_reuslt truncate partition ',@partition_name);
prepare stmt from @stat;
execute stmt;
set @stat=concat('alter table tb_trade_blotter_op_sec_liquidity_risk truncate partition ',@partition_name);
prepare stmt from @stat;
execute stmt;
set @stat=concat('alter table tb_bond_price_comparision_trade_blotter_op_sec_mul truncate partition ',@partition_name);
prepare stmt from @stat;
execute stmt;
</update>
```
2. 在spring boot的service层代码中,添加以下方法:
```
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
public void truncatePartitions(String batchDate) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("batchDate", batchDate);
sqlSessionTemplate.update("truncatePartitions", paramMap);
}
```
3. 调用truncatePartitions方法,即可执行相关的truncate partition语句。例如:
```
truncatePartitions("20230222");
```
阅读全文