定时任务及list集合数据入库mybatis对应sql书写

本文介绍如何将yyMMdd时间格式转换为yyyy-MM-dd样式,以及如何在Spring框架中配置定时任务,实现方法的自动定时执行。同时,还提供了将List集合数据批量插入数据库的MyBatis示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、yyMMdd时间格式转换为yyyy-MM-dd时间样式

    function reverseTo(value, row, index) {
        return changeDateFormat(value)
    }

    function changeDateFormat(cellval) {

        if (cellval.length == 8) {
            valDate = cellval.substring(0, 4) + "-" + cellval.substring(4, 6) + "-" + cellval.substring(6, 8);
            return valDate;
        } else if (cellval.length == 6) {
            valDate = cellval.substring(0, 4) + "-" + cellval.substring(4, 6);
            return valDate;
        }
        return valDate;
    }

2、自动定时执行:在方法上配置注解
@Lazy(false)
@Scheduled(cron = “0/5 * * * * ?”):每隔5秒执行一次
并在spring-context.xml中配置:
xmlns:tx=“http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
然后加入:<task:annotation-driven /> 自动扫描任务

3、将list集合数据插入数据的方法:

    <insert id="insertTimeInfo" parameterType="java.util.List" useGeneratedKeys="true">
        insert into AWX_VIP_KEY_INFO_DAILY
        (cust_name, vip_card, vip_cust_name, crm_cust_id, latn_id, create_date, state_date, state,
        domain_name, key_cn_nbr, manager_id, cust_star,rela_phs_nbr,staff_name,area_path,etl_state,file_id,vipkey_type)
        values
        <!--该collection针对list集合必须将参数设置为对应所要插入的集合keyInfoList-->
        <foreach collection="keyInfoList" item="item" index="index" separator=",">
            (
            #{item.custName},
            #{item.vipCard},
            #{item.vipCustName},
            #{item.crmCustId},
            #{item.latnId},
            #{item.createDate},
            #{item.stateDate},
            #{item.state},
            #{item.domainName},
            #{item.keyCnNbr},
            #{item.managerId},
            #{item.custStar},
            #{item.relaPhsNbr},
            #{item.staffName},
            #{item.areaPath},
            #{item.etlState},
            #{item.fileId},
            #{item.vipkeyType}
            )
        </foreach>
    </insert>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值