用<a>传值问题

本文介绍如何在SpringMVC应用中利用HTML的a标签将参数传递到控制器的方法。通过示例代码展示了如何定义带有参数的链接,并在控制器端接收并处理这些参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

写springmvc的时候需要把请求中的值传回controller,用道路<a>标签

具体用法看代码

<a href="commidselect?commid=${commodity.commid }">

    /*
     * 按commid查询
     */
    @RequestMapping("/commidselect")
    public String commidselect(int commid,HttpServletRequest request){//springmvc可以自动类型转化
        Commodity commodity=commodityService.selectByCommid(commid);
        request.setAttribute("commodity",commodity);
        return "commidselect";
    }



#include <iostream> #include <vector> #include <queue> #include <climits> #include <algorithm> using namespace std; // 方向数组:上、下、左、右 const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; // 检查水位t时是否存在路径 bool check(int t, const vector<vector<int>>& grid) { int n = grid.size(); vector<vector<bool>> visited(n, vector<bool>(n, false)); queue<pair<int, int>> q; // 起点必须被淹没 if (grid[0][0] > t) return false; q.push({0, 0}); visited[0][0] = true; while (!q.empty()) { auto [x, y] = q.front(); q.pop(); // 到达终点 if (x == n-1 && y == n-1) return true; // 探索四个方向 for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; // 检查边界和访问状态 if (nx < 0 || ny < 0 || nx >= n || ny >= n || visited[nx][ny]) continue; // 检查是否被淹没 if (grid[nx][ny] <= t) { visited[nx][ny] = true; q.push({nx, ny}); } } } return false; } int main() { int n; cin >> n; vector<vector<int>> grid(n, vector<int>(n)); int max_height = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> grid[i][j]; max_height = max(max_height, grid[i][j]); } } // 二分查找最小T int low = max(grid[0][0], grid[n-1][n-1]); int high = max_height; int ans = high; while (low <= high) { int mid = low + (high - low) / 2; if (check(mid, grid)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } cout << ans << endl; return 0; } 将变量简化到一个字母,删除注释和不必要的缩进,使用万能头文件,去除const vector<vector<int>>& grid
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值