到目前为止,我正在创建这样的端点:
@RequestMapping(value = "/test", method = RequestMethod.POST)
public @ResponseBody String indexPost(HttpServletRequest request, HttpServletResponse response)
throws Exception {
//Doing calculations
return "Result";
}
但我想在服务器启动时访问 application.properties ,读出存储的数据,如下所示:
methods: {
"endpointOne": "DBStoredProcedure1",
"endpointTwo": "DBStoredProcedure2"
}
So 当我的 Spring Boot 应用程序启动时,它将根据属性文件创建所有 POST 端点带有第一个参数的名称(如“endpointOne”),并将调用定义为第二个参数(如“DBStoredProcedure1”)的存储过程(并返回其结果)。
可以做吗?
是的你可以。不过与您现在尝试做的事情有点不同。
最好是使用“PathVariable” - 您可以在此处找到详细信息:
https://spring.io/guides/tutorials/bookmarks/
http://javabeat.net/spring-mvc-requestparam-pathvariable/
您在 Controller 类中的方法将如下所示:
@RequestMapping(value="/{endPoint}", method=RequestMethod.POST)
public String endPoint(@PathVariable String endPoint) {
//Your endPoint is now the one what the user would like to reach
//So you check if your property file contains this String - better to cache it's content
//If it does, you call the service with the regarding Stored Procedure.
String sPName = prop.getSPName(endPoint); //You need to implement it.
String answer = yourService.execute(sPName);
return answer;
}
显然,您需要实现一种方法来处理属性文件中未找到的那些查询,但您明白了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)