发表于: 2019-10-29 22:26:22
1 559
今天完成的事情:
使用mybatis-geneator插件生成代码,编写Service代码
生成实体类,dao接口和接口配置文件
dao接口
@Repository
public interface AuthorMessageDao {
int deleteByPrimaryKey(Integer authorId);
int insert(AuthorMessage record);
int insertSelective(AuthorMessage record);
AuthorMessage selectByPrimaryKey(Integer authorId);
int updateByPrimaryKeySelective(AuthorMessage record);
int updateByPrimaryKey(AuthorMessage record);
}
dao接口配置文件
<?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.dao.AuthorMessageDao">
<resultMap id="BaseResultMap" type="com.pojo.AuthorMessage">
<id column="author_id" jdbcType="INTEGER" property="authorId" />
<result column="tourist_id" jdbcType="INTEGER" property="touristId" />
<result column="work_id" jdbcType="INTEGER" property="workId" />
<result column="author_name" jdbcType="VARCHAR" property="authorName" />
<result column="author_comment" jdbcType="VARCHAR" property="authorComment" />
<result column="creat_at" jdbcType="BIGINT" property="creatAt" />
<result column="creat_by" jdbcType="VARCHAR" property="creatBy" />
<result column="update_at" jdbcType="BIGINT" property="updateAt" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
</resultMap>
<sql id="Base_Column_List">
author_id, tourist_id, work_id, author_name, author_comment, creat_at, creat_by,
update_at, update_by
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from author_message
where author_id = #{authorId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from author_message
where author_id = #{authorId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pojo.AuthorMessage">
insert into author_message (author_id, tourist_id, work_id,
author_name, author_comment, creat_at,
creat_by, update_at, update_by
)
values (#{authorId,jdbcType=INTEGER}, #{touristId,jdbcType=INTEGER}, #{workId,jdbcType=INTEGER},
#{authorName,jdbcType=VARCHAR}, #{authorComment,jdbcType=VARCHAR}, #{creatAt,jdbcType=BIGINT},
#{creatBy,jdbcType=VARCHAR}, #{updateAt,jdbcType=BIGINT}, #{updateBy,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.pojo.AuthorMessage">
insert into author_message
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="authorId != null">
author_id,
</if>
<if test="touristId != null">
tourist_id,
</if>
<if test="workId != null">
work_id,
</if>
<if test="authorName != null">
author_name,
</if>
<if test="authorComment != null">
author_comment,
</if>
<if test="creatAt != null">
creat_at,
</if>
<if test="creatBy != null">
creat_by,
</if>
<if test="updateAt != null">
update_at,
</if>
<if test="updateBy != null">
update_by,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="authorId != null">
#{authorId,jdbcType=INTEGER},
</if>
<if test="touristId != null">
#{touristId,jdbcType=INTEGER},
</if>
<if test="workId != null">
#{workId,jdbcType=INTEGER},
</if>
<if test="authorName != null">
#{authorName,jdbcType=VARCHAR},
</if>
<if test="authorComment != null">
#{authorComment,jdbcType=VARCHAR},
</if>
<if test="creatAt != null">
#{creatAt,jdbcType=BIGINT},
</if>
<if test="creatBy != null">
#{creatBy,jdbcType=VARCHAR},
</if>
<if test="updateAt != null">
#{updateAt,jdbcType=BIGINT},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pojo.AuthorMessage">
update author_message
<set>
<if test="touristId != null">
tourist_id = #{touristId,jdbcType=INTEGER},
</if>
<if test="workId != null">
work_id = #{workId,jdbcType=INTEGER},
</if>
<if test="authorName != null">
author_name = #{authorName,jdbcType=VARCHAR},
</if>
<if test="authorComment != null">
author_comment = #{authorComment,jdbcType=VARCHAR},
</if>
<if test="creatAt != null">
creat_at = #{creatAt,jdbcType=BIGINT},
</if>
<if test="creatBy != null">
creat_by = #{creatBy,jdbcType=VARCHAR},
</if>
<if test="updateAt != null">
update_at = #{updateAt,jdbcType=BIGINT},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
</set>
where author_id = #{authorId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pojo.AuthorMessage">
update author_message
set tourist_id = #{touristId,jdbcType=INTEGER},
work_id = #{workId,jdbcType=INTEGER},
author_name = #{authorName,jdbcType=VARCHAR},
author_comment = #{authorComment,jdbcType=VARCHAR},
creat_at = #{creatAt,jdbcType=BIGINT},
creat_by = #{creatBy,jdbcType=VARCHAR},
update_at = #{updateAt,jdbcType=BIGINT},
update_by = #{updateBy,jdbcType=VARCHAR}
where author_id = #{authorId,jdbcType=INTEGER}
</update>
</mapper>
实体类
public class AuthorMessage implements Serializable {
/**
* 作者ID
*/
private Integer authorId;
/**
* 游客ID
*/
private Integer touristId;
/**
* 作品ID
*/
private Integer workId;
/**
* 作品名称
*/
private String authorName;
/**
* 回复内容
*/
private String authorComment;
/**
* 创建时间
*/
private Long creatAt;
/**
* 创建人
*/
private String creatBy;
/**
* 更新时间
*/
private Long updateAt;
/**
* 更新人
*/
private String updateBy;
private static final long serialVersionUID = 1L;
public Integer getAuthorId() {
return authorId;
}
public void setAuthorId(Integer authorId) {
this.authorId = authorId;
}
public Integer getTouristId() {
return touristId;
}
public void setTouristId(Integer touristId) {
this.touristId = touristId;
}
public Integer getWorkId() {
return workId;
}
public void setWorkId(Integer workId) {
this.workId = workId;
}
public String getAuthorName() {
return authorName;
}
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
public String getAuthorComment() {
return authorComment;
}
public void setAuthorComment(String authorComment) {
this.authorComment = authorComment;
}
public Long getCreatAt() {
return creatAt;
}
public void setCreatAt(Long creatAt) {
this.creatAt = creatAt;
}
public String getCreatBy() {
return creatBy;
}
public void setCreatBy(String creatBy) {
this.creatBy = creatBy;
}
public Long getUpdateAt() {
return updateAt;
}
public void setUpdateAt(Long updateAt) {
this.updateAt = updateAt;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
AuthorMessage other = (AuthorMessage) that;
return (this.getAuthorId() == null ? other.getAuthorId() == null : this.getAuthorId().equals(other.getAuthorId()))
&& (this.getTouristId() == null ? other.getTouristId() == null : this.getTouristId().equals(other.getTouristId()))
&& (this.getWorkId() == null ? other.getWorkId() == null : this.getWorkId().equals(other.getWorkId()))
&& (this.getAuthorName() == null ? other.getAuthorName() == null : this.getAuthorName().equals(other.getAuthorName()))
&& (this.getAuthorComment() == null ? other.getAuthorComment() == null : this.getAuthorComment().equals(other.getAuthorComment()))
&& (this.getCreatAt() == null ? other.getCreatAt() == null : this.getCreatAt().equals(other.getCreatAt()))
&& (this.getCreatBy() == null ? other.getCreatBy() == null : this.getCreatBy().equals(other.getCreatBy()))
&& (this.getUpdateAt() == null ? other.getUpdateAt() == null : this.getUpdateAt().equals(other.getUpdateAt()))
&& (this.getUpdateBy() == null ? other.getUpdateBy() == null : this.getUpdateBy().equals(other.getUpdateBy()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getAuthorId() == null) ? 0 : getAuthorId().hashCode());
result = prime * result + ((getTouristId() == null) ? 0 : getTouristId().hashCode());
result = prime * result + ((getWorkId() == null) ? 0 : getWorkId().hashCode());
result = prime * result + ((getAuthorName() == null) ? 0 : getAuthorName().hashCode());
result = prime * result + ((getAuthorComment() == null) ? 0 : getAuthorComment().hashCode());
result = prime * result + ((getCreatAt() == null) ? 0 : getCreatAt().hashCode());
result = prime * result + ((getCreatBy() == null) ? 0 : getCreatBy().hashCode());
result = prime * result + ((getUpdateAt() == null) ? 0 : getUpdateAt().hashCode());
result = prime * result + ((getUpdateBy() == null) ? 0 : getUpdateBy().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", authorId=").append(authorId);
sb.append(", touristId=").append(touristId);
sb.append(", workId=").append(workId);
sb.append(", authorName=").append(authorName);
sb.append(", authorComment=").append(authorComment);
sb.append(", creatAt=").append(creatAt);
sb.append(", creatBy=").append(creatBy);
sb.append(", updateAt=").append(updateAt);
sb.append(", updateBy=").append(updateBy);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
service接口
public interface AuthorMessageService {
void deleteByPrimaryKey(Integer authorId);
void insert(AuthorMessage record);
void insertSelective(AuthorMessage record);
AuthorMessage selectByPrimaryKey(Integer authorId);
void updateByPrimaryKeySelective(AuthorMessage record);
void updateByPrimaryKey(AuthorMessage record);
serviceimpl
@Service("AuthorMessageService")
public class AuthorMessageServiceImpl implements AuthorMessageService {
@Autowired
private AuthorMessageDao authorMessageDao;
@Override
public void deleteByPrimaryKey(Integer authorId) {
authorMessageDao.deleteByPrimaryKey(authorId);
}
@Override
public void insert(AuthorMessage authorMessage) {
authorMessageDao.insert(authorMessage);
}
@Override
public void insertSelective(AuthorMessage record) {
authorMessageDao.insertSelective(record);
}
@Override
public AuthorMessage selectByPrimaryKey(Integer authorId) {
return authorMessageDao.selectByPrimaryKey(authorId);
}
@Override
public void updateByPrimaryKeySelective(AuthorMessage record) {
authorMessageDao.updateByPrimaryKeySelective(record);
}
@Override
public void updateByPrimaryKey(AuthorMessage record){
authorMessageDao.updateByPrimaryKey(record);
}
明天计划的事情:准备小课堂资料
遇到的问题:在build的plugins中添加mybatis-geneator插件依赖时爆红,改用了师兄推荐的安装版
收获:学会使用mybatis-geneator插件生成代码
评论