sql查询注意

2019-06-05  本文已影响0人  6默默Welsh

select * 查询全表所有字段这样写不好,因为数据库随着业务不断发展,字段也在不断增加,查表时要什么查什么,我们可以这样先定义sql标签比如:

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

然后这样

  <select id="selectLogin" parameterType="map" resultMap="BaseResultMap">
    SELECT
    // 使用 include 标签重用重用mybatis的代码段
   <include refid="Base_Column_List" />
    from mmall_user
    where username = #{username}
    and password = #{password}
  </select>

updateByPrimaryKeySelective 和 updateByPrimaryKey区别:

updateByPrimaryKeySelective会对字段进行判断再更新(如果为Null就忽略更新),如果你只想更新某一字段,可以用这个方法。
updateByPrimaryKey对你注入的字段全部更新

上一篇 下一篇

猜你喜欢

热点阅读