mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-14 06:03:52 +08:00
WebFlux 整合 Thymeleaf
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package org.spring.springboot.dao;
|
||||
|
||||
import org.spring.springboot.domain.City;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@Repository
|
||||
public class CityRepository {
|
||||
|
||||
private ConcurrentMap<Long, City> repository = new ConcurrentHashMap<>();
|
||||
|
||||
private static final AtomicLong idGenerator = new AtomicLong(0);
|
||||
|
||||
public Long save(City city) {
|
||||
Long id = idGenerator.incrementAndGet();
|
||||
city.setId(id);
|
||||
repository.put(id, city);
|
||||
return id;
|
||||
}
|
||||
|
||||
public Collection<City> findAll() {
|
||||
return repository.values();
|
||||
}
|
||||
|
||||
|
||||
public City findCityById(Long id) {
|
||||
return repository.get(id);
|
||||
}
|
||||
|
||||
public Long updateCity(City city) {
|
||||
repository.put(city.getId(), city);
|
||||
return city.getId();
|
||||
}
|
||||
|
||||
public Long deleteCity(Long id) {
|
||||
repository.remove(id);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user