永远爱学习

导航

Python与springboot的对接

使用springboot建立一个web demo ,其中有一个接口如下,为了测试加了一个参数 type:

 @Autowired
private JdbcTemplate jdbcTemplate;

@RequestMapping(value = "/getCountry", method = RequestMethod.GET)
// @ResponseBody
public List<Map<String, Object>> getUser(@RequestBody Map<String, Object> reqMap) {
String type = reqMap.get("type").toString();
switch (type) {

case "test":
List<Map<String, Object>> jj = new ArrayList<>();
Map<String, Object> jd = new HashMap<>();
jd.put("123", "test");
jj.add(jd);
return jj;
default:
String sql = "select * from country";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
return list;
}

}


如果使用Python 可能不会使用这么多的代码,但有时为了性能不得不做出让步,那就用Python来开发页面以及不太需要运行速度的模块:
rep = requests.get(url='http://localhost:8080/getCountry', json={"type": "test"})
print(
json.loads(rep.text))


posted on 2019-01-24 13:36  永远爱学习  阅读(7795)  评论(0)    收藏  举报