Springboot前后端交互问题...

天才韩神 2020-01-23 06:29:18

这是我的前后端 无论点提交还是Test Method都取不到前端的值 小白一枚 还请各位指教
...全文
506 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qnimal 2020-02-13
  • 打赏
  • 举报
回复
具体实现:
<form action="http://localhost:8081/UserController/formtest" method="post" >
id值:<input type="text" name="id" />
<br>
<input type="submit" value="查询" />
</form>
<a href="http://localhost:8081/UserController/formtest?id=1">链接</a>
------------------------------------------------------------------------------------
@RequestMapping(value = "formtest"
,method = RequestMethod.POST
)
@ResponseBody
public Object formtest(String id,HttpServletRequest request){

Integer idvalue = Integer.valueOf(id);
return userService.selectUserById(idvalue);
}
qnimal 2020-02-13
  • 打赏
  • 举报
回复
4l+1. and,你的第二个testmethod是个超链接,相当于浏览器打了个get,压根儿没参数后端怎么接...
kimi-001 2020-02-06
  • 打赏
  • 举报
回复
action的问题,只用了类和方法上的requestmapping没有加访问项目的路径
流泪熊猫头 2020-01-25
  • 打赏
  • 举报
回复
是因为controller方法参数没有加 @RequestParam 注解吧
黑白猿 2020-01-24
  • 打赏
  • 举报
回复
首先需要界定你自己发送GET还是POST请求,再去进行下一步调查。下面是根据你的说明,给出的一个GET方法的例子。请参考。 前端HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="http://localhost:9002/gavin/path/getPath?name=zhangsan">Test Get Method</a>
</body>
</html>
后端代码
package com.gavinbj.confmng.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/path")
public class HelloController {
	

    @GetMapping("/getPath")
    public String hello(@RequestParam(value="name", required = true) String name) {
    	
        return "This is test API." + name;
    }
}
返回结果
心怀啊 2020-01-24
  • 打赏
  • 举报
回复
哈哈的那个input添加id=name

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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