我在一个名为calculator.java
的文件中有下面的Spring程序
@RestController
public class Calculator {
@RequestMapping("/calculate")
public int calculate(@RequestParam("expression") String expression) {
// parse the expression
int result = 0;
String[] tokens = expression.split("(\\+|-|\\*|/)");
for (String token : tokens) {
result += Integer.parseInt(token);
}
// return the result
return result;
}
}
我已经尝试过使用spring run
启动它(我已经安装了Spring ),但是它不能工作。文档非常混乱,我需要做些什么才能从浏览器中以"/calculate“中的端点启动这个/calculate文件?
谢谢。
发布于 2022-07-07 04:10:08
步骤1:查看Linux域或IP。
步骤2:查看tomcat启动端口和上下文路径的内容。
步骤3:打开浏览器输入
http://{linux domain or IP}:{tomcat started port}/{context path}/calculate?expression=test
示例:
http://127.0.0.1:8080/test/calculate?expression=test
https://stackoverflow.com/questions/72891962
复制相似问题