ssm批量删除和模糊查询
来源:互联网 发布:网络论坛营销方案 编辑:程序博客网 时间:2024/06/06 11:02
1.Dao层方法
package com.tcc.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.tcc.bean.student;
import com.tcc.bean.type;
public interface usermapper {
//此处用到了注解@param它可以用来拼接到sql中
public List<student> list(@Param("sname")String sname);
public void delete(Integer id);
public student inli(student st);
}
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.tcc.bean.student;
import com.tcc.bean.type;
public interface usermapper {
//此处用到了注解@param它可以用来拼接到sql中
public List<student> list(@Param("sname")String sname);
public void delete(Integer id);
public student inli(student st);
}
2.Dao层实现类
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tcc.dao.usermapper">
<select id="list" parameterType="student" resultMap="stu">
select * from t_student s,t_class c where s.cid=c.id
<if test="sname!=null">
and s.name like '%${sname}%' //判断出条件 拼接sql
</if>
</select>
<delete id="delete">
delete from t_student where id=#{id}
</delete>
</mapper>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tcc.dao.usermapper">
<select id="list" parameterType="student" resultMap="stu">
select * from t_student s,t_class c where s.cid=c.id
<if test="sname!=null">
and s.name like '%${sname}%' //判断出条件 拼接sql
</if>
</select>
<delete id="delete">
delete from t_student where id=#{id}
</delete>
</mapper>
3.Controller
package com.tcc.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.tcc.bean.student;
import com.tcc.bean.type;
import com.tcc.service.userservice;
@Controller
@RequestMapping("user")
public class controller {
@Autowired
private userservice us;
@RequestMapping("list")
public String list(String sname,Model model){
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.tcc.bean.student;
import com.tcc.bean.type;
import com.tcc.service.userservice;
@Controller
@RequestMapping("user")
public class controller {
@Autowired
private userservice us;
@RequestMapping("list")
public String list(String sname,Model model){
List<student> list = us.list(sname);
model.addAttribute("list", list);
return "success";
}
@RequestMapping("delete")
model.addAttribute("list", list);
return "success";
}
@RequestMapping("delete")
//批量删除会有多个id这里用String[] ids来接收
public String delete(String[] ids){
//循环遍历让每一个id都执行删除方法
for (String string : ids) {
us.delete(Integer.parseInt(string));
}
return "redirect:/user/list";
}
}
us.delete(Integer.parseInt(string));
}
return "redirect:/user/list";
}
}
3.jsp-jquery
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
<script type="text/javascript">
$(function(){
$(".qx").click(function () { $("input[type=checkbox]:gt(0)").prop("checked",this.checked);})//全选反选
$("#全选标签id").click(function(){
var array=new Array;
$("input[type=checkbox]:gt(0):checked").each(function(){
array.push($(this).parent().next().text());
});
alert(array);
location.href="${pageContext.request.contextPath}/user/delete?ids="+array;
});
});
</script>
var array=new Array;
$("input[type=checkbox]:gt(0):checked").each(function(){
array.push($(this).parent().next().text());
});
alert(array);
location.href="${pageContext.request.contextPath}/user/delete?ids="+array;
});
});
</script>
<form action="****.action">//调用查询方法,把sname传到后台 <input type="text" name="sname">//sanme就是@param里面所写的参数 <input type="submit" value="查询"></form>
阅读全文
3 0
- ssm批量删除和模糊查询
- Mybatis批量查询和模糊查询
- StackExchange.Redis加载Lua脚本进行模糊查询的批量删除和修改
- 模糊查询,批量删除, 添加用户,隔行变色,排序,过滤器
- AngularJS排序+模糊查询+批量删除+添加列表
- SSM做批量删除
- SSM SpringMVC 批量删除
- SSM框架 用ajax实现模糊查询分页和列表
- 用户信息的增删改查:非空验证添加,模糊查询,修改密码,批量和全部删除
- Redis模糊查询、模糊删除
- Mybatis批量增加、批量更新、批量删除和查询
- 【ssm个人博客项目实战08】博客的分页显示以及模糊查询,删除。
- SSM 框架的批量删除
- html angular+route:模糊查询+限定年龄范围+全部删除+批量删除+修改密码+添加用户
- 隔行换色+删除+批量删除+排序+模糊查询+修改+添加
- java memcached客户端,模糊查询/批量删除/查询所有的key
- 商品增加和查询、排序、批量删除、批量发货
- easyUI(七) -- SSM+easyUI 级联模糊查询
- leetcode
- Android零基础入门第25节:简单且最常用的LinearLayout线性布局
- linux下的后台处理
- vue:一群java后台死在配置上
- MySQL5.7性能优化系列(二)——SQL语句优化(2)——使用 Semi-Join半连接变换优化子查询,派生表和视图
- ssm批量删除和模糊查询
- Linux C线程总结(1)
- Java基础概念
- SQL替换字段中部分字符
- Educational Codeforces Round 24
- Linux C++ zookeeper创建临时节点类封装
- springData是什么,深入理解
- 在使用django 的过程中难免的会使用到format表单进行提交,如果出现“CSRF验证失败. 相应中断”.该如何解决呢?
- 数字分隔(二)