spring mybatis 集成, springmvc参数引起后台操作数据库问题

chen_bq 2015-04-28 10:01:23
springmvc mybatis 集成,如果以如下ajax方法传参数时,则删除不成功!
	
function deleteUser() {

var ids=getSelectedIds();

if(ids.length!=0){
$.dialog.confirm('你确定要删除用户吗?', function(){
$.ajax({
type : "POST",
url : "${ctx}/sys/user/delete",
dataType : "json",
data : {userIds:JSON.stringify(ids)},
success : function(resp) {

tip(resp.message);
if(resp.flag){
reloadDataTable();
}
}
});
}, function(){

});

}else{
tip('请选择要删除的用户');
}

};


@RequestMapping(value = "delete", method = RequestMethod.POST)
@ResponseBody
public AjaxMessage deleteUser(@RequestParam("userIds") List<String> userIds ) {
try {

userService.delete(userIds );
AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户成功");
return ajaxMessage;
} catch (ServiceException e) {
AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户失败");
return ajaxMessage;
}
}
}


如下代码,ajax参数代码不是数组时,则可以正常删除数据

function deleteUser() {

var ids=getSelectedIds();

if(ids.length!=0){
$.dialog.confirm('你确定要删除用户吗?', function(){
$.ajax({
type : "POST",
url : "${ctx}/sys/user/delete",
dataType : "json",
data : {userIds:ids[0]},
success : function(resp) {

tip(resp.message);
if(resp.flag){
reloadDataTable();
}
}
});
}, function(){

});

}else{
tip('请选择要删除的用户');
}

};

@RequestMapping(value = "delete", method = RequestMethod.POST)
@ResponseBody
public AjaxMessage deleteUser(@RequestParam("userIds") String userId) {
try {

userService.delete(userId);
AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户成功");
return ajaxMessage;
} catch (ServiceException e) {
AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户失败");
return ajaxMessage;
}
}
...全文
407 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
scl666 2016-05-30
  • 打赏
  • 举报
回复
你这问题到现在都没解决吗 怎么还在这挂着
chen_bq 2015-04-29
  • 打赏
  • 举报
回复
怎么没有人遇到时类似的问题呢
chen_bq 2015-04-29
  • 打赏
  • 举报
回复
引用 8 楼 xiaxiaolin_yun 的回复:
你这个当然删除不了,这样传递相当于一次删除多条数据。要用批量删除
一次删除多条数据? 这种的代码不支持? userService代码 @Transactional @Override public void delete(List<String> userIds) throws ServiceException { for (String userId : userIds) { userDao.delete(userId); } }
Braska 2015-04-29
  • 打赏
  • 举报
回复
sql语句打印出来,拿到数据库执行。
尼坤神 2015-04-29
  • 打赏
  • 举报
回复
你这个当然删除不了,这样传递相当于一次删除多条数据。要用批量删除
chen_bq 2015-04-29
  • 打赏
  • 举报
回复
引用 6 楼 chen_bq 的回复:
这样可以删除的,就是页面以数组形式传到controller时,dao就删除不了数据


function deleteUser() {
			
			var ids=getSelectedIds();
			
			if(ids.length!=0){
				$.dialog.confirm('你确定要删除用户吗?', function(){
					$.ajax({
						type : "POST",
						url : "${ctx}/sys/user/delete",
						data : {userIds: ids.join(',')},  
						success : function(resp) {
							
							tip(resp.message);
							if(resp.flag){
								reloadDataTable(); 
							}
						}
					});







@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public AjaxMessage deleteUser(@RequestParam("userIds") String userIds) {
		try {
			List<String> userIdList=new ArrayList<String>();
			for(String userId:userIds.split(",")){
				userIdList.add(userId);
			}
			userService.delete(userIdList);
			AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户成功");
			return ajaxMessage;
		} catch (ServiceException e) {
			AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户失败");
			return ajaxMessage;
		}
	}



这样传参时,就删除不了,参数可以一直传递到dao层的
function deleteUser() {
             
            var ids=getSelectedIds();
             
            if(ids.length!=0){
                $.dialog.confirm('你确定要删除用户吗?', function(){
                    $.ajax({
                        type : "POST",
                        url : "${ctx}/sys/user/delete",
                        dataType : "json",
                        data : {userIds:JSON.stringify(ids)},  
                        success : function(resp) {
                             
                            tip(resp.message);
                            if(resp.flag){
                                reloadDataTable(); 
                            }
                        }
                    });
                }, function(){
                    
                });
                 
            }else{
                tip('请选择要删除的用户');
            }
                
        };
 
 
@RequestMapping(value = "delete", method = RequestMethod.POST)
    @ResponseBody
    public AjaxMessage deleteUser(@RequestParam("userIds") List<String> userIds ) {
        try {
             
            userService.delete(userIds );
            AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户成功");
            return ajaxMessage;
        } catch (ServiceException e) {
            AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户失败");
            return ajaxMessage;
        }
    }
    }
chen_bq 2015-04-29
  • 打赏
  • 举报
回复
这样可以删除的,就是页面以数组形式传到controller时,dao就删除不了数据


function deleteUser() {
			
			var ids=getSelectedIds();
			
			if(ids.length!=0){
				$.dialog.confirm('你确定要删除用户吗?', function(){
					$.ajax({
						type : "POST",
						url : "${ctx}/sys/user/delete",
						data : {userIds: ids.join(',')},  
						success : function(resp) {
							
							tip(resp.message);
							if(resp.flag){
								reloadDataTable(); 
							}
						}
					});







@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public AjaxMessage deleteUser(@RequestParam("userIds") String userIds) {
		try {
			List<String> userIdList=new ArrayList<String>();
			for(String userId:userIds.split(",")){
				userIdList.add(userId);
			}
			userService.delete(userIdList);
			AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户成功");
			return ajaxMessage;
		} catch (ServiceException e) {
			AjaxMessage ajaxMessage = new AjaxMessage(true, "删除用户失败");
			return ajaxMessage;
		}
	}


chen_bq 2015-04-29
  • 打赏
  • 举报
回复
userService代码 @Transactional @Override public void delete(List<String> userIds) throws ServiceException { for (String userId : userIds) { userDao.delete(userId); } }
fengyu_caihong 2015-04-29
  • 打赏
  • 举报
回复
你穿过去的是数组~可能你dao处理的时候有问题~把你穿过的数组字符串当做id删除了当然删除不了~你好好看看你的dao吧~而且你也没判断穿过的字符串是数组组成的串还是只是id~后台你自己根本就没区分,传数组怎么可能正常~
chen_bq 2015-04-29
  • 打赏
  • 举报
回复
引用 2 楼 u010880076 的回复:
进方法没咯。。
当然进方法了,都进dao了
程序袁_哈哈 2015-04-29
  • 打赏
  • 举报
回复
进方法没咯。。
项目描述 在上家公司自己集成的一套系统,用了两个多月的时间完成的:Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级开发系统 Springboot作为容器,使用mybatis作为持久层框架 使用官方推荐的thymeleaf做为模板引擎,shiro作为安全框架,主流技术 几乎零XML,极简配置 两套UI实现(bootstrap+layer ui),可以自由切换 报表后端采用技术: SpringBoot整合SSM(Spring+Mybatis-plus+ SpringMvc),spring security 全注解式的权限管理和JWT方式禁用Session,采用redis存储token及权限信息 报表前端采用Bootstrap框架,结合Jquery Ajax,整合前端Layer.js(提供弹窗)+Bootstrap-table(数据列表展示)+ Bootstrap-Export(各种报表导出SQL,Excel,pdf等)框架,整合Echars,各类图表的展示(折线图,饼图,直方图等),使用了layui的弹出层、菜单、文件上传、富文本编辑、日历、选项卡、数据表格等 Oracle关系型数据库以及非关系型数据库(Redis),Oracle 性能调优(PL/SQL语言,SQL查询优化,存储过程等),用Redis做中间缓存,缓存数据 实现异步处理,定时任务,整合Quartz Job以及Spring Task 邮件管理功能, 整合spring-boot-starter-mail发送邮件等, 数据源:druid 用户管理,菜单管理,角色管理,代码生成 运行环境 jdk8+oracle+redis+IntelliJ IDEA+maven 项目技术(必填) Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis 数据库文件 压缩包内 jar包文件 maven搭建 Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统 http://localhost:/8080/login admin admin Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统
项目描述 在上家公司自己集成的一套系统,用了两个多月的时间完成的:Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级开发系统 Springboot作为容器,使用mybatis作为持久层框架 使用官方推荐的thymeleaf做为模板引擎,shiro作为安全框架,主流技术 几乎零XML,极简配置 两套UI实现(bootstrap+layer ui),可以自由切换 报表后端采用技术: SpringBoot整合SSM(Spring+Mybatis-plus+ SpringMvc),spring security 全注解式的权限管理和JWT方式禁用Session,采用redis存储token及权限信息 报表前端采用B ootstrap框架,结合Jquery Ajax,整合前端Layer.js(提供弹窗)+Bootstrap-table(数据列表展示)+ Bootstrap-Export(各种报表导出SQL,Excel,pdf等)框架,整合Echars,各类图表的展示(折线图,饼图,直方图等),使用了layui的弹出层、菜单、文件上传、富文本编辑、日历、选项卡、数据表格等 Oracle关系型数据库以及非关系型数据库(Redis),Oracle 性能调优(PL/SQL语言,SQL查询优化,存储过程等),用Redis做中间缓存,缓存数据 实现异步处理,定时任务,整合Quartz Job以及Spring Task 邮件管理功能, 整合spring-boot-starter-mail发送邮件等, 数据源:druid 用户管理,菜单管理,角色管理,代码生成 运行环境 jdk8+oracle+redis+IntelliJ IDEA+maven 项目技术(必填) Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis 数据库文件 压缩包内 jar包文件 maven搭建 Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统 http://localhost:/8080/login admin admin Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统
郑重声明:本文分享系统来自互联网,分享目的在于传递更多信息,帮助大家,并不代表本人赞同其观点和 对其真实性负责。如涉及作品内容、版权和其它问题,请在七日内与本人联系,我将在第一时间删除内容! [声明]本站文章版权归原作者所有,内容为作者个人观点,本人只提供参考并不构成任何投资及应用建议。 本人拥有对此声明的最终解释权。 系统完全开源, 系统包含如下: 登陆,注销,修改 系统管理:菜单管理,操作员管理,角色管理,操作员授权。 站点管理:站点信息管理,站点类型。 由于密码是涉及加密,请勿在数据库中任意修改密码 简要说明 使用Java平台,采用SpringMVC+Mybatis等主流框架 数据库:使用免费MYSQL 前端:使用Jquery和Easyui技术.界面清晰简洁,易操作. 权限:对菜单,按钮控制.仅展示有权限的菜单和按钮. 拦截:对所有无权限URL进行拦截,防止手动发送HTTP请求,确保系统全性. 代码生成:根据表生成对应的Bean,Service,Mapper,Action,XML等。提高开发效率. 项目说明: 用户名:admin 密 码:为大家方便,我已把密码放到登陆页,无需输入密码即可登陆 运行环境: 硬件平台: CPU:酷睿II。 内存:1GB以上。 软件平台: 操作系统:Windows。 数据库:MySQL。 编程平台:eclipse 浏览器:IE Web服务器:tomcat 分辨率:最佳效果1024×768像素。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧