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))



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM