由于之前主要使用的是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);
}



