Skip to content

sql如何查询表中特定的字段

select * 不好,因为一个表里的字段有可能很多,应该需要什么字段就查什么

xml
  <select id="selectLogin" resultMap="BaseResultMap" parameterType="map">
    SELECT
    --     *???//这样真的好么?答案就是,这样不好.
    <include refid="Base_Column_List" />
    from mmall_user
    where username = #{username}
    and password = #{password}
  </select>

可以先定义好Base_Column_List,在sql中使用include指定查询的字段

xml
  <sql id="Base_Column_List" >
    id, username, password, email, phone, question, answer, role, create_time, update_time
  </sql>

如有转载或 CV 的请标注本站原文地址