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