mybatis sql

————获取所有的数据

@GetMapping("/getAll1")
	public AjaxResult list1(String name,String userId) {
		User user = userMapper.selectByPrimaryKey(Integer.valueOf(userId));
		Map<String,String> param = new HashMap<String, String>();
		param.put("name", name);
		param.put("parentId", "0");
		if(!user.getType().equals(1)) {
			param.put("userId", userId);
		}
		List<Application> list =  applicationMapper.wxSelectData(param);
		return AjaxResult.success(list);
	}
List<Application> wxSelectData(@Param("param") Map<String, String> param);
 <select id="wxSelectData" parameterType="hashmap" resultType="com.ruoyi.weixin.model.Application">
        select id,name,icon,parent_id parentId,type from application
        where parent_id=#{param.parentId}
        <if test="param.name!=null and param.name !=''">
			and name like '%${param.name}%'
		</if>
		 <if test="param.userId!=null and param.userId !=''">
			and id in (select application_id from application_user where user_id = #{param.userId})
		</if>
    </select>

----------------删除数据

 	@PostMapping(value = "save")
    @ApiOperation(value = "修改保存应用")
    public AjaxResult save(@RequestBody User user)
    {
        applicationUserMapper.deleteApplicationUserByUserId(user.getId());
        for(Integer i: user.getCheckedKeys()){
            applicationUserMapper.insert(new ApplicationUser(user.getId(),i,null));
        }
        return  AjaxResult.success("修改成功");
    }
void deleteApplicationUserByUserId(@Param("userId") Integer userId);
   <delete id="deleteApplicationUserByUserId" parameterType="int">
		delete from application_user where
		user_id=#{userId}
	</delete>

---------返回Map 类型,返回单条记录为Map

public Map<String, Object> selectEmployee(Integer id);
<select id="selectEmployee" resultType="java.util.Map">
        select * from employee where id=#{id}
  </select>

----执意任意的SQL查询语句,返回List<HashMap<String,Object>>对象

 List<Map<String,Object>> CommonQuery(@Param(value = "strsql") String strsql);
<select id="CommonQuery"  resultType="hashmap"  >
<![CDATA[ ${strsql}]]> 
</select>

StringBuilder sb = new StringBuilder(“SELECT af.DATA1 ‘total’,af.EFFECT_DATE1000 ‘aDate’,af.DATA2 ‘instantValue’,af.DATA4 ‘reverseValue’,af.DATA3 ‘positiveValue’,af.DATA6 ‘hydraulicValue’,af.STATUS ‘mStatus’,");
sb.append(" ii.NAME ‘iName’,ii.I_ID ‘iId’,");
sb.append(" ie.NAME ‘eName’,ie.STATUS ‘iStatus’,ie.ELECTRICITY ‘electricity’,ie.E_Id ‘iPhone’,ie.TIME
1000 ‘updateTime’,ie.SIGNAL_VALUE ‘signalValue’,”);
sb.append(" de.NAME ‘dName’");
sb.append(" FROM i_instrument ii");
sb.append(" left join i_equipment ie");
sb.append(" ON ii.E_ID = ie.E_ID");
sb.append(" LEFT JOIN d_enterprise de");
sb.append(" ON ii.ENT_ID = de.E_ID");
sb.append(" LEFT JOIN “+type+” af");
sb.append(" ON ii.I_ID = af.I_ID");
sb.append(" where 1=1 “);
sb.append(” AND af.M_ID IS NOT NULL ");

sb.toString();

------返回多个map

List<Map<String, Object>> getWaterInfo(@Param("iId")String iId);
<select id="getWaterInfo" resultType="map">
SELECT <include refid="Base_Column_List" />
FROM h_flow
WHERE I_ID = #{iId}
ORDER BY D_DATE DESC
</select>

—————–删除

void deleteDeviceTypeByPid(@Param("pid")Integer pid);
   <delete id="deleteDeviceTypeByPid" parameterType="int">
		delete from device_type where
		pid=#{pid}
	</delete>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_38325017

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值