1. 程式人生 > >將資料庫的表反向生成實體類

將資料庫的表反向生成實體類

1、SpringBoot逆向生成工具

注意事項:

生成的mapper.xml檔案,就是實體類的每一個屬性和資料庫表的每一個列相對應:

VideosMapper.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.imooc.mapper.VideosMapper" >
  <resultMap id="BaseResultMap" type="com.imooc.pojo.Videos" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="user_id" property="userId" jdbcType="VARCHAR" />
    <result column="audio_id" property="audioId" jdbcType="VARCHAR" />
    <result column="video_desc" property="videoDesc" jdbcType="VARCHAR" />
    <result column="video_path" property="videoPath" jdbcType="VARCHAR" />
    <result column="video_seconds" property="videoSeconds" jdbcType="REAL" />
    <result column="video_width" property="videoWidth" jdbcType="INTEGER" />
    <result column="video_height" property="videoHeight" jdbcType="INTEGER" />
    <result column="cover_path" property="coverPath" jdbcType="VARCHAR" />
    <result column="like_counts" property="likeCounts" jdbcType="BIGINT" />
    <result column="status" property="status" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>
</mapper>

VideosMapper.java類

public interface VideosMapperCustom extends MyMapper<Videos> {
	
	/**
	 * @Description: 條件查詢所有視訊列表
	 */
	public List<VideosVO> queryAllVideos(@Param("videoDesc") String videoDesc,
			@Param("userId") String userId);
	
	/**
	 * @Description: 查詢關注的視訊
	 */
	public List<VideosVO> queryMyFollowVideos(String userId);
	
	/**
	 * @Description: 查詢點贊視訊
	 */
	public List<VideosVO> queryMyLikeVideos(@Param("userId") String userId);
	
	/**
	 * @Description: 對視訊喜歡的數量進行累加
	 */
	public void addVideoLikeCount(String videoId);
	
	/**
	 * @Description: 對視訊喜歡的數量進行累減
	 */
	public void reduceVideoLikeCount(String videoId);
}