Java 日常开发笔记(小程序页面交互传参-id)

发布于:2025-08-11 ⋅ 阅读:(17) ⋅ 点赞:(0)

前端代码

传id

  // 使用 JSON.stringify 将数组转换为字符串,以符合 URL 的要求
  del(`/system/wenjuan/${id}`).then(res => {
    if (res.code == 200) {
      uni.showToast({
        title: '删除成功',
        icon: 'success',    // 将值设置为 success 或者 ''
        duration: 2000    // 持续时间为 2秒
      });
    } else {
      uni.showToast({
        title: '删除失败',
        icon: 'error',    // 将值设置为 success 或者 ''
        duration: 2000    // 持续时间为 2秒
      });
    }
  });

传数组ids

方式一

const ids = [id];
  // 使用 JSON.stringify 将数组转换为字符串,以符合 URL 的要求
  del(`/system/wenjuan/${ids.join('/')}`).then(res => {
    if (res.code == 200) {
      uni.showToast({
        title: '删除成功',
        icon: 'success',    // 将值设置为 success 或者 ''
        duration: 2000    // 持续时间为 2秒
      });
    } else {
      uni.showToast({
        title: '删除失败',
        icon: 'error',    // 将值设置为 success 或者 ''
        duration: 2000    // 持续时间为 2秒
      });
    }
  });

js交互代码

// 删除公共方法
export function del(url) {
    return request({
        url: url,
        method: 'delete'
    })
}

方式二

del(`/system/wenjuan/`,ids).then(res => {
   if (res.code == 200) {
     uni.showToast({
       title: '删除成功',
       icon: 'success',
       duration: 2000
     });
     that.getlist(); // 刷新列表
   } else {
     uni.showToast({
       title: '删除失败',
       icon: 'error',
       duration: 2000
     });
   }
 });

js交互代码

// 删除公共方法
export function del(url,roleId) {
    return request({
        url: url + roleId,
        method: 'delete'
    })
}

后端接口

接收ids

@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
    return toAjax(wenjuanService.deleteWenjuanByIds(ids));
}

接收id

@DeleteMapping("/{id}")
public AjaxResult remove(@PathVariable int ds)
{
    return toAjax(wenjuanService.deleteWenjuanById(id));
}

网站公告

今日签到

点亮在社区的每一天
去签到