• java mybatis


    mybatis简单使用记录一下

    mybatis官网:http://www.mybatis.org/mybatis-3/

    参考博客:https://blog.csdn.net/iku5200/article/details/82856621

    配置

    application.properties

    mybatis.mapper-locations:classpath:/mapping/*.xml
    mybatis.config-location:classpath:/mybatis-config.xml

    model表(略)

    dao层:

    import org.apache.ibatis.annotations.Mapper;
    
    import java.util.List;
    
    
    @Mapper
    public interface TestConfigMapper {
        List<TestConfigEntity> findAll();
        int upsertBatch(List<TestConfigEntity> list);
    }

    mapping/mapping.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <mapper namespace="com.sensor.xxx.dao.TestConfigMapper">  <!-- 指向dao层 -->
    
        <select id="findAll" resultType="com.sensor.xxx.models.TestConfigEntity">  <!-- 返回一个列表,列表中的元素type是 entity对象 -->
                select * from vibration_config  <!-- sql语句 -->
        </select>
    
        <insert id="upsertBatch" parameterType="java.util.List">  <!-- 批量操作foreach循环 -->
            insert into vibration_config (point_id, duration)
            values
            <foreach collection="list" item="item" index="index" separator=",">  <!-- jdbcType 指定映射类型 -->
                (#{item.pointId,jdbcType=VARCHAR},#{item.duration,jdbcType=INTEGER})  <!-- 如果不写括号,可以用参数指定:open="(" separator="," close=")"-->
    </foreach>
    ON conflict(point_id)
    do update set
    duration
    = excluded.duration
    </insert>
    </mapper>

    第二个是批量 没有添加,有就更新(postgres)

    ====

    批量删除

       <delete id="deleteBatch" parameterType="java.util.List">
            delete from vibration_alarm_realtime where point_id in
            <foreach collection="list" item="point_id" open="(" separator="," close=")">
                #{point_id}
            </foreach>
        </delete>
    
        <delete id="deleteAll">
            delete from vibration_alarm_realtime
        </delete>
  • 相关阅读:
    FPGA基础学习(2) -- FIFO IP核(Quartus)
    FPGA中如何实现除法?
    GPIO初始化之PB3/PB4/PA13/PA14/PA15引脚的复用--寄存器版本
    图像处理实际应用启发
    霍夫变换(hough transform)
    傅里叶变换讲解
    模拟电路学习入门的建议(综合整理)
    低噪声APD偏置电路
    如何安装altium designer 10
    后仿真
  • 原文地址:https://www.cnblogs.com/zhzhlong/p/11435678.html
Copyright © 2020-2023  润新知