标签:des os java ar sp c sql res type
方法一:在sql中添加case when
实体和字段的映射
<resultMap id="RM_PlanProjects" type="cn.bidlink.yuecai.plan.model.PlanProjects"> <result property="disabled" column="disabled"/> </resultMap>
SQL语句:
<select id="decomposeProjectListPage" resultMap="RM_PlanProjects">
SELECT
id,project_id,project_name,project_type,project_status,create_time,project_code,
(case project_status
when 8 then true
when 7 then true
else false end) disabled
FROM plan_plan_projects
WHERE plan_id =#{planId} AND company_id = #{companyId} AND project_status != #{projectStatus}
<if test=" createTime != null">
ORDER BY create_time desc
</if>
</select>
实体对象:
private boolean disabled;
public boolean isDisabled() {
return disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
方法二、个人感觉更加合理,方便维护,简单!比较推荐
直接在实体对象中添加控制
private boolean disabled;
public boolean isDisabled() {
return (this.getProjectStatus().equals(Integer.valueOf(7))|| this.getProjectStatus().equals(Integer.valueOf(8)));
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
返回给前台的时候自动更加相关信息做控制。
标签:des os java ar sp c sql res type
原文地址:http://my.oschina.net/u/260244/blog/307728