課程
/后端開發(fā)
/Java
/Spring Boot 2.0深度實(shí)踐-初遇Spring Boot
在RouterFunctionConfiguration中創(chuàng)建的findall方法后,需要去UserRepository中返回Map存儲: return?repository.values();
2019-05-16
源自:Spring Boot 2.0深度實(shí)踐-初遇Spring Boot 2-4
正在回答
/** ?*?{@link?User}?{@link?Repository} ?*/ @Repository public?class?UserRepository?{ ????/** ?????*?采用內(nèi)存型的存儲方式->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(); //????????設(shè)置ID ????????user.setId(id); ????????return?repository.put(id,?user)?==?null; ????} ????/** ?????*?返回所有用戶 ?????* ?????*?@return ?????*/ ????public?Collection<User>?findAll()?{ ????????return?repository.values(); ????} }
舉報
Spring Boot 2.x/Web Flux/多模塊化項目實(shí)踐
1 回答使用函數(shù)式編程,在 get 請求返回404
7 回答post方法沒有問題,但是get方法為什么返回404?debug時不走方法
2 回答多模塊的Controller能訪問,但是找不到j(luò)sp是什么問題
4 回答404報錯而且我啟動的時候也看不到我的PostMapping,localhost也訪問不了
1 回答webful 404》?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2019-06-06