Flask接口签名sign原理与实例代码浅析
203
2023-07-07
深入浅出MyBatis中映射文件和实体类的关联性
mybatis的映射文件写法多种多样,不同的写法和用法,在实际开发过程中所消耗的开发时间、维护时间有很大差别,今天我就把我认为比较简单的一种映射文件写法记录下来,供大家修改建议,争取找到一个最优写法~~:
以User对象和UserMap.xml为例讲解,代码如下:
User为用户实体类(仅作为讲解,可以只关注引用类型变量,get/set方法省略):
import com.google.common.collect.Lists;
import com.gukeer.common.persistence.DataEntity;
import com.gukeer.modules.personal.entity.Dept;
import com.gukeer.modules.personal.entity.Staff;yFflDJ
import com.gukeer.modules.school.entity.School;
import java.util.Date;
/**
* 用户Entity
*
* auther:cc
* date:2016/9/2
*/
public class User extends DataEntity
private static final long serialVersionUID = 1L;
private String id;
private Office company; // 归属公司
private Office office; // 归属部门
private String loginName;// 登录名
private String password;// 密码
private String no; // 工号
private String name; // 姓名
private String email; // 邮箱
private String phone; // 电话
private String mobile; // 手机
private String userType;// 用户类型
private String loginIp; // 最后登陆IP
private Date loginDate; // 最后登陆日期
private String loginFlag; // 是否允许登陆
private String photo; // 头像
private String qrCode; // 二维码
private String oldLoginName;// 原登录名
private String newPassword; // 新密码
private String oldLoginIp; // 上次登陆IP
private Date oldLoginDate; // 上次登陆日期
private Dept dept; //部门
private Staff staff; //职位
private Role role; // 根据角色查询用户条件
private List
private School school; //归属学校
private String remarks; // 备注
private User createBy; // 创建者
private Date createDate; // 创建日期
private User updateBy; // 更新者
private Date updateDate; // 更新日期
private String delFlag; // 删除标记(0:正常;1:删除;2:审核)
}
针对引用类型的成员变量,为了可以在查询过程中直接赋值,在映射文件中可以直接将查询结果赋值给返回的结果集:
a.id,
a.company_id AS "company.id",
a.office_id AS "office.id",
a.login_name,
a.password,
a.no,
a.name,
a.email,
a.phone,
a.mobile,
a.user_type,
a.login_ip,
a.login_date,
a.remarks,
a.login_flag,
a.photo,
a.qrcode,
a.create_by AS "createBy.id",
a.create_date,
a.update_by AS "updateBy.id",
a.update_date,
a.del_flag,
c.name AS "company.name",
c.parent_id AS "company.parent.id",
c.parent_ids AS "company.parentIds",
ca.id AS "company.area.id",
ca.name AS "company.area.name",
ca.parent_id AS "company.area.parent.id",
ca.parent_ids AS "company.area.parentIds",
o.name AS "office.name",
o.parent_id AS "office.parent.id",
o.parent_ids AS "office.parentIds",
oa.id AS "office.area.id",
oa.name AS "office.area.name",
oa.parent_id AS "office.area.parent.id",
oa.parent_ids AS "office.area.parentIds",
cu.id AS "company.primaryPerson.id",
cu.name AS "company.primaryPerson.name",
cu2.id AS "company.deputyPerson.id",
cu2.name AS "company.deputyPerson.name",
ou.id AS "office.primaryPerson.id",
ou.name AS "office.primaryPerson.name",
ou2.id AS "office.deputyPerson.id",
ou2.name AS "office.deputyPerson.name",
sc.xxlx AS "school.xxlx",
sc.xxmc AS "school.xxmc"
LEFT JOIN sys_office c ON c.id = a.company_id
LEFT JOIN sys_area ca ON ca.id = c.area_id
LEFT JOIN sys_office o ON o.id = a.office_id
LEFT JOIN sys_area oa ON oa.id = o.area_id
LEFT JOIN sys_user cu ON cu.id = c.primary_person
LEFT JOIN sys_user cu2 ON cu2.id = c.deputy_person
LEFT JOIN sys_user ou ON ou.id = o.primary_person
LEFT JOIN sys_user ou2 ON ou2.id = o.deputy_person
LEFT JOIN xj_school sc ON sc.id = a.school
SELECT
FROM sys_user a
WHERE a.id = #{id}
SELECT
FROM sys_user a
WHERE
a.login_name = #{loginName}
AND a.del_flag = #{DEL_FLAG_NORMAL}
INSERT INTO sys_user(
id,
company_id,
office_id,
login_name,
password,
no,
name,
email,
phone,
mobile,
user_type,
create_by,
create_date,
update_by,
update_date,
remarks,
login_flag,
photo,
qrcode,
del_flag,
dept_id,
staff_id,
school
) VALUES (
#{id},
#{company.id},
#{office.id},
#{loginName},
#{password},
#{no},
#{name},
#{email},
#{phone},
#{mobile},
#{userType},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{loginFlag},
#{photo},
#{qrCode},
#{delFlag},
#{dept.id},
#{staff.id},
#{school.id}
)
UPDATE sys_user SET
company_id = #{company.id},
office_id = #{office.id},
login_name = #{loginName},
password = #{password},
no = #{no},
name = #{name},
email = #{email},
phone = #{phone},
mobile = #{mobile},
user_type = #{userType},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks},
login_flag = #{loginFlag},
photo = #{photo},
qrcode = #{qrCode},
school = #{school.id}
WHERE id = #{id}
DELETE FROM sys_user
WHERE id = #{id}
UPDATE sys_user SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~