mybatis中将map作为参数的写法

mybatis中将map作为参数的写法

dao层
public  List  getSql(Map<String, Object> resultmap);

mapper文件

在这里插入图片描述

controller层

		if (mainPojo.getSource().equals("1")) {
			String sql = mainPojo.getMainSql(); //select * from user where user = #{this} and code = #{code} and id = #{id}
			if(sql.contains("#{this}")) {
			 	sql = sql.replaceAll("#{this}", ShiroKit.getPrincipal().getUsername()); 
			}
			String param = mainPojo.getMainParam();
			Map resultmap = new HashMap();
			resultmap.put("sql",sql);
			if (param != null) {
				String[] params = param.split(",");  // id=1,code=AAAAA
				for (String    p : params) {
					resultmap.put(p.split("=")[0], p.split("=")[1]);
				}
			}
			List resultmaps =dBRunnerService.getSql(resultmap);
			Map result = new HashMap();
			result.put("sqlValue", resultmaps);
			result.put("mainName",mainPojo.getMainName());
			result.put("mainUrl",mainPojo.getMainUrl());
			result.put("mainUrlName",mainPojo.getMainUrlName());
			result.put("mainTitle",mainPojo.getMainTitle());
			result.put("type",mainPojo.getType());
			return ResultVo.success(result);
		} else {
			return ResultVo.error(2000, "暂无数据");
		}

你可能感兴趣的:(mybatis中将map作为参数的写法)