栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Springboot+mybatis实现增删改查

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Springboot+mybatis实现增删改查

由于之前主要使用的是Springboot+JPA实现数据的查询,在使用Springboot+mybatis开发时,查询了许多文章,现在整理如下,供大家参阅!
1、CarBaseinfo对象结构

public class CarBaseinfo {
    
    private Integer id;
    
    private String communityId;
    
    private Integer peopleId;
    
    private String color;
    
    private String brand;

    
    private String plate;

    
    private String plateColor;

    
    private Integer isApply;


    
    private long createTime;

    
    private long updateTime;

    //省略getter、setter方法
}

2、Mapper实现代码

import com.genersoft.iot.vmp.info.entity.CarBaseinfo;
import org.apache.ibatis.annotations.*;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;


@Mapper
@Repository
public interface CarBaseinfoMapper {

    
    @Select("SELECT id," +
            "community_id    AS communityId, " +
            "people_id       AS peopleId, " +
            "color           AS color, " +
            "brand           AS brand, " +
            "plate, " +
            "plate_color     AS plateColor, " +
            "is_apply        AS isApply, " +
            "create_time     AS createTime," +
            "update_time     AS updateTime " +
            "FROM car_baseinfo WHERe id = #{id}")
    CarBaseinfo queryById(Integer id);

    
    @Select(value = {" "})
    List queryByPage(CarBaseinfo carBaseinfo);

    
    @Select("SELECT count(1) FROM car_baseinfo ")
    long count(CarBaseinfo carBaseinfo);

    
    @Insert("INSERT INTO car_baseinfo (" +
            "community_id, " +
            "people_id, " +
            "color, " +
            "brand, " +
            "plate, " +
            "plate_color, " +
            "is_apply, " +
            "create_time," +
            "update_time" +
            ") VALUES (" +
            "#{communityId}," +
            "#{peopleId}," +
            "#{color}," +
            "#{brand}," +
            "#{plate}," +
            "#{plateColor}," +
            "#{isApply}," +
            "#{createTime}," +
            "#{updateTime}" +
            ")")
    int insert(CarBaseinfo carBaseinfo);

    
    @Insert(" ")
    int insertBatch(@Param("carBaseinfos") List carBaseinfos);

    
    @Insert(" ")
    int insertOrUpdateBatch(@Param("carBaseinfos") List carBaseinfos);

    
    @Update(value = {" "})
    int update(CarBaseinfo carBaseinfo);

    
    @Delete("DELETE FROM car_baseinfo WHERe id=#{id}")
    int deleteById(Integer id);

}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/972458.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号