1.Mybatis根据有无值进行修改
mybatis的trim标签一般用于去除sql语句中多余的and关键字,逗号,或者给sql语句前拼接 “where“、“set“以及“values(“ 等前缀,或者添加“)“等后缀,可用于选择性插入、更新、删除或者条件查询等操作。
<update id="updateAdminByParam" parameterType="admin">
update t_admin
-- suffixOverrides:如果最后一个是有值的可以把逗号去掉
<trim prefix="set" suffixOverrides=",">
<if test="username!=null">
username=#{username} ,
</if>
<if test="password!=null">
password=#{password},
</if>
<if test="contactinformation!=null">
contactinformation=#{contactinformation},
</if>
<if test="lastmodifiedate!=null">
lastmodifiedate=#{lastmodifiedate},
</if>
</trim>
<where>
id=#{id}
</where>
</update>
2.删除全选,通过JQuery获取复选框选中的id值
var chk_value =[];
$("#deleteAllBtn").click(function () {
$('input[name="ids"]:checked').each(function(){
chk_value.push($(this).val());
});
console.log(chk_value)
})
3.Mybatis的参数
@Param注解的作用是给参数命名,参数命名后就能根据名字得到参数值,正确的将参数传入sql语句中
使用foreach标签
<delete id="deleteAdminByIds" parameterType="int">
delete from t_admin
<where>
id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</where>
</delete>
3.RequestMapping可以匹配多个路径
@RequestMapping(value = {
"/do/admin/admin_deleteAll/{pageNum}/{keyword}.html",
"/do/admin/admin_deleteAll/{keyword}.html",
"/do/admin/admin_deleteAll/{pageNum}.html"}
)
4.获取复选框的值
var ids=[];
$('input[name="ids"]:checked').each(function(){
ids.push($(this).val());
});
console.log(ids)