发表于: 2018-10-19 21:02:23
1 307
今天完成的事情:(一定要写非常细致的内容,比如说学会了盒子模型,了解了Margin)
今天主要完成的是意见反馈接口的编写。
在编写意见反馈接口的时候,由于涉及了3表联查,所以我在写相应的接口时,考虑是否使一对多的方式进行,不过在认真考虑之后,发现在搜索的时候,由于其条件查询的条件是在3个表中的数据,所以使用起来传参并不容易。要不就构造一个新pojo去传参,要不就是使用Map去传参,在考虑之下。我觉得使用一个新的VO类去接受返回的连表查询类和条件查询入参。
其ideaVO:
package com.iceneet.opreation.vo;
/**
* @Author: 快乐水 零度可乐
* @Description:
* @Date: Created in 9:16 2018/10/20
* @Modified By:
*/
public class IdeaVo {
private Long id;
private String serialId;
private Long replyTime;
private Boolean status;
private Long createdAt;
private String content;
private String phoneNumber;
private String realName;
private String account;
}
其IdeaMapper.xml:
<resultMap id="IdeasMap" type="com.iceneet.opreation.vo.IdeaVo" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="serial_id" property="serialId" jdbcType="VARCHAR" />
<result column="Reply_by" property="replyBy" jdbcType="BIGINT" />
<result column="Reply_time" property="replyTime" jdbcType="BIGINT" />
<result column="status" property="status" jdbcType="BIT" />
<result column="account" property="account" jdbcType="VARCHAR" />
<result column="created_at" property="createdAt" jdbcType="BIGINT" />
<result column="phone_number" property="phoneNumber" jdbcType="VARCHAR" />
<result column="real_name" property="realName" jdbcType="VARCHAR" />
<result column="content" property="content" jdbcType="LONGVARCHAR" />
</resultMap>
<select id="getIdeas" resultMap="IdeasMap">
SELECT
t1.id ,t1.serial_id,t1.content,t1.Reply_time,t1.status,t1.created_at,
t2.real_name,
t2.phone_number,
t3.account
from idea t1
LEFT Join user t2 on t1.user_id = t2.id
LEFT JOIN manager t3 on t1.Reply_by=t3.id
</select>
<select id="selectChoosenIdeas" resultMap="IdeasMap" parameterType="com.iceneet.opreation.vo.IdeaVo">
SELECT
t1.id ,t1.serial_id,t1.content,t1.Reply_time,t1.status,t1.created_at,
t2.real_name,
t2.phone_number,
t3.account
from idea t1
LEFT Join user t2 on t1.user_id = t2.id
LEFT JOIN manager t3 on t1.Reply_by=t3.id
<where>
<if test="serialId != null">
t1.serial_id like "%"#{serialId}"%"
</if>
<if test="content != null">
and t1.content like "%"#{content}"%"
</if>
<if test="realName != null">
and t2.real_name like "%"#{realName}"%"
</if>
<if test="phoneNumber != null">
and phone_number like "%"#{phoneNumber}"%"
</if>
</where>
</select>
其Mapper接口:
public interface IdeaMapper {
int deleteByPrimaryKey(Long id);
int insert(Idea record);
int insertSelective(Idea record);
Idea selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(Idea record);
int updateByPrimaryKeyWithBLOBs(Idea record);
int updateByPrimaryKey(Idea record);
List<IdeaVo> getIdeas();
List<IdeaVo> selectChoosenIdeas(IdeaVo ideaVo);
}
明天计划的事情:继续编写接口
遇到的问题:(遇到什么困难,怎么解决的)
收获:(通过今天的学习,学到了什么知识)
评论