課程
/后端開發
/Java
/Spring Boot 2.0深度實踐-初遇Spring Boot
在RouterFunctionConfiguration中創建的findall方法后,需要去UserRepository中返回Map存儲: return?repository.values();
2019-05-16
源自:Spring Boot 2.0深度實踐-初遇Spring Boot 2-4
正在回答
/** ?*?{@link?User}?{@link?Repository} ?*/ @Repository public?class?UserRepository?{ ????/** ?????*?采用內存型的存儲方式->Map ?????*/ ????private?final?ConcurrentMap<Integer,?User>?repository?=?new?ConcurrentHashMap<>(); ????private?final?static?AtomicInteger?idGenerator?=?new?AtomicInteger(); ????/** ?????*?保存用戶對象 ?????* ?????*?@param?user?{@link?User}?對象 ?????*?@return?如果保存成功,返回<code>true</code>, ?????*?否則返回<code>false</code> ?????*/ ????public?boolean?save(User?user)?{ ????????//ID從1開始 ????????Integer?id?=?idGenerator.incrementAndGet(); //????????設置ID ????????user.setId(id); ????????return?repository.put(id,?user)?==?null; ????} ????/** ?????*?返回所有用戶 ?????* ?????*?@return ?????*/ ????public?Collection<User>?findAll()?{ ????????return?repository.values(); ????} }
舉報
Spring Boot 2.x/Web Flux/多模塊化項目實踐
1 回答使用函數式編程,在 get 請求返回404
7 回答post方法沒有問題,但是get方法為什么返回404?debug時不走方法
2 回答多模塊的Controller能訪問,但是找不到jsp是什么問題
4 回答404報錯而且我啟動的時候也看不到我的PostMapping,localhost也訪問不了
1 回答webful 404》?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-06-06