angular - Angular,当 url 中提到变量时,变量不会被其值替换。例如:${用户名}
问题描述
我在springboot中使用@pathvariable从客户端接收数据。变量是用户名、密码和电子邮件。
我检查了变量的值是否传递给了服务。是的,当我在控制台日志中打印它时,它就通过了。
当变量在 url 中分配为 /${username)/${password)//${email) 时,不是获取这些变量的值,而是 ${username) 存储在数据库中,而不是输入的用户名在用户界面中。
通过 Postman 验证,url 中指定的值用于在数据库中创建记录,工作正常。
附上 Rest Controller 代码和服务代码:
Rest Controller
_________________
@RestController
public class UserResource {
@Autowired
private UserService userService;
@RequestMapping(value = "/user/{username}/{password}/{email}",
method = RequestMethod.POST)
public ResponseEntity newUserPost(@PathVariable("username") String username,
@PathVariable("password") String password,
@PathVariable("email") String email,
HttpServletResponse response)
throws Exception {
registerUser function in Service
________________________________
registerUser(username: string, password: string, email: string) {
let params = 'username='+username+'&password='+password;
console.log(params);
let url = 'http://localhost:8080/user/${username}/${password}/${email}'
let headers = new HttpHeaders({
'Content-Type' : 'application/x-www-form-urlencoded',
});
return this.http.post(url, {headers: headers, responseType : 'text'});
}
变量的值需要发送到弹簧靴。
解决方案
if 应该包裹在 `` 不是单个 qoutes 周围
let url = `http://localhost:8080/user/${username}/${password}/${email}`
推荐阅读
- powershell - 如何通过 csv 文件读取输入并将输出写入 power shell 脚本的输出文件?
- python - python将json嵌套到具有指定标题的csv/xlsx
- quarkus - Quarkus AWS S3 支持的库
- html - 如何在mpdf中获得完整的图像宽度
- javascript - 接口的实现需要在类中重新声明成员
- go - Cron 作业没有按照使用 Golang 的预定时间运行
- r - 条件分割和聚合
- javascript - 一些机构可以帮助我在 angularjs 中使用 ng-mouseover 和 ng-mouseleave 吗?
- firebase - Firebase 云消息传递 API 控制台 - 定位用户
- java - Android 使用 PSK 和用户/密码连接到 VPN 服务器 (IPSec)