这是我的 Controller :
@Controller
@RequestMapping("/test")
public class TestServlet {
@RequestMapping("/country/{latitude}-{longitude}")
public String getCountry(@PathVariable String latitude, @PathVariable String longitude, Model model){
//inject the data in the JSP
model.addAttribute("latitude", latitude);
model.addAttribute("longitude", longitude);
//return the html
return "private/private";
}
我想知道如何使用 JavaScript 代码中的参数访问此方法。
public String getCountry(@PathVariable String latitude, @PathVariable String longitude, Model model);
最佳答案
像这样就可以了
$.ajax({
type : "GET",
url : "http://<server>:<port>/test/country/<latitudevalue>-<longitudevalue>",
contentType: "application/json",
dataType: "json",
success : function (data, status) {
......
},
error : function (status) {
....
}
});
关于javascript - 从 JavaScript 调用 Java 代码(Spring boot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47927916/