提升sql运行效率的小技巧
<!--为什么要这么写?这样写可以提高sql的运行效率。而写*,需要Oracle去数据库查出字段名,再拼接查询-->
<sql id="Base_Column_List" >
ID, PRO_PARAM_DETAIL_ID, START_VALUE, END_VALUE, SCORE_CONTENT, CREATE_DATE, DATA_FLAG
</sql>
<select id="selectStuProScoreList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from ASSESS_STU_PRO_SCORE
</select>
查询主表是一条数据、副表是多条数据时的小技巧。展开的一对多的数据格式。多对多则外面接List
po实体类
public class BaseLoginUser{
private Integer id;
private String userName;
private List<BaseRoleList> roleList;
get和set方法。
}
Mapper层
public BaseLoginUser updUserById(Integer id);
<resultMap type="com.jykj.po.powermanage.BaseLoginUser" id="baseLoginRoleInfo">
//表1的数据一一对应
<id column="id" property="id"/>
<result column="username" property="userName"/>
<collection property="roleList" ofType="com.jykj.po.powermanage.BaseRoleList">
//表2的数据一一对应
<id column="roleId" property="id"/>
<result column="rolename" property="roleName"/>
</collection>
</resultMap>
<!-- magen 2018/8/7 用户管理,修改用户,查询用户信息。输入用户ID -->
<select id="updUserById" parameterType="Integer" resultMap="baseLoginRoleInfo">
select * from 表1 left join 表2 on 表1.列=表2.列 where 表1.id=#{id}
</select>