发表于: 2019-11-10 23:39:39
1 897
主要完成账户管理模块。
三、遇到的问题:
在做修改账户信息功能时,对其操作是,先删除账户角色关系表的信息,再进行修改账户表的信息。
功能完成后,对接口进行测试,没有报错,但数据库信息没有更新。
debug才是知道,数据库填的假数据,有的账户在关系表里没有关联角色信息,删除的操作就失败了,而这一步也没有做出判断,直接跳出,返回到controller里,由于没报错,就直接返回请求成功。一致于调了好久,也没发现问题。
解决方法:1.要假数据要合适,正确。2.代码逻辑也要做好异常处理。
四、收获:
1.完成账户管理的全部接口,功能基本实现。
账户管理的接口各个功能和角色管理相似,省去了多思考的时间,直接上手干就行了。
2.联表动态查询sql.
<!-- 动态查询 列表-->
<select id="selectList" parameterType="com.happynewyear.admin.pojo.Account" resultMap="BaseResultMap" >
select a.id id ,a.name name,r.`name` roleName,a1.name createByName,a.create_at
from account a
left join account_role ar on a.id=ar.account_id
left join role r on r.id = ar.role_id
left join account a1 on a.create_by = a1.id
<where>
<if test="name != null and name !=''">
a.name LIKE '%${name}%'
</if>
<if test="roleId != null and roleId !=''">
and r.id= #{roleId,jdbcType=BIGINT}
</if>
<if test="startTime != null and startTime !=''">
and a.create_at >= #{startTime,jdbcType=BIGINT}
</if>
<if test="endTime != null and endTime !=''">
and a.create_at <= #{endTime,jdbcType=BIGINT}
</if>
</where>
</select>
3.在Mybatis中,mapper.xml文件中的特殊字符要进行转义。
评论