diff --git a/springboot-webflux-10-book-manage-sys/pom.xml b/springboot-webflux-10-book-manage-sys/pom.xml index 320c7a3c..9b98898b 100644 --- a/springboot-webflux-10-book-manage-sys/pom.xml +++ b/springboot-webflux-10-book-manage-sys/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - WebFlux 实战图书管理系统 + WebFlux 实战城市管理系统 demo.springboot springboot-webflux-10-book-manage-sys diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/dao/BookRepository.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/dao/CityRepository.java similarity index 60% rename from springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/dao/BookRepository.java rename to springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/dao/CityRepository.java index adc52e9f..f8add5d1 100644 --- a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/dao/BookRepository.java +++ b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/dao/CityRepository.java @@ -1,10 +1,10 @@ package demo.springboot.dao; -import demo.springboot.domain.Book; +import demo.springboot.domain.City; import org.springframework.data.mongodb.repository.ReactiveMongoRepository; import org.springframework.stereotype.Repository; @Repository -public interface BookRepository extends ReactiveMongoRepository { +public interface CityRepository extends ReactiveMongoRepository { } diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/domain/Book.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/domain/Book.java deleted file mode 100644 index 39417c6d..00000000 --- a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/domain/Book.java +++ /dev/null @@ -1,68 +0,0 @@ -package demo.springboot.domain; - -import org.springframework.data.annotation.Id; - -import java.io.Serializable; - -/** - * Book 实体类 - * - * Created by bysocket - */ -public class Book implements Serializable { - - private static final long serialVersionUID = 8033624715179323397L; - - /** - * 编号 - */ - @Id - private Long id = 0L; - - /** - * 书名 - */ - private String name; - - /** - * 作者 - */ - private String writer; - - /** - * 简介 - */ - private String introduction; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getWriter() { - return writer; - } - - public void setWriter(String writer) { - this.writer = writer; - } - - public String getIntroduction() { - return introduction; - } - - public void setIntroduction(String introduction) { - this.introduction = introduction; - } -} diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/domain/City.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/domain/City.java new file mode 100644 index 00000000..2fa0a5cf --- /dev/null +++ b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/domain/City.java @@ -0,0 +1,60 @@ +package demo.springboot.domain; + +/** + * 城市实体类 + * + */ +public class City { + + /** + * 城市编号 + */ + private Long id; + + /** + * 省份编号 + */ + private Long provinceId; + + /** + * 城市名称 + */ + private String cityName; + + /** + * 描述 + */ + private String description; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getProvinceId() { + return provinceId; + } + + public void setProvinceId(Long provinceId) { + this.provinceId = provinceId; + } + + public String getCityName() { + return cityName; + } + + public void setCityName(String cityName) { + this.cityName = cityName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/BookService.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/BookService.java deleted file mode 100644 index 00b39ad3..00000000 --- a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/BookService.java +++ /dev/null @@ -1,45 +0,0 @@ -package demo.springboot.service; - -import demo.springboot.domain.Book; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -/** - * Book 业务接口层 - * - * Created by bysocket - */ -public interface BookService { - /** - * 获取所有 Book - */ - Flux findAll(); - - /** - * 新增 Book - * - * @param book {@link Book} - */ - Mono insertByBook(Book book); - - /** - * 更新 Book - * - * @param book {@link Book} - */ - Mono update(Book book); - - /** - * 删除 Book - * - * @param id 编号 - */ - Mono delete(Long id); - - /** - * 获取 Book - * - * @param id 编号 - */ - Mono findById(Long id); -} diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/CityService.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/CityService.java new file mode 100644 index 00000000..6d260bce --- /dev/null +++ b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/CityService.java @@ -0,0 +1,18 @@ +package demo.springboot.service; + +import demo.springboot.domain.City; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public interface CityService { + + Flux findAll(); + + Mono insertByCity(City city); + + Mono update(City city); + + Mono delete(Long id); + + Mono findById(Long id); +} diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/impl/BookServiceImpl.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/impl/BookServiceImpl.java deleted file mode 100644 index 38bdc93e..00000000 --- a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/impl/BookServiceImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -package demo.springboot.service.impl; - -import demo.springboot.dao.BookRepository; -import demo.springboot.domain.Book; -import demo.springboot.service.BookService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -/** - * Book 业务层实现 - * - * Created by bysocket - */ -@Component -public class BookServiceImpl implements BookService { - - private final BookRepository bookRepository; - - @Autowired - public BookServiceImpl(BookRepository bookRepository) { - this.bookRepository = bookRepository; - } - - @Override - public Flux findAll() { - return bookRepository.findAll(); - } - - @Override - public Mono insertByBook(Book book) { - return bookRepository.save(book); - } - - @Override - public Mono update(Book book) { - return bookRepository.save(book); - } - - @Override - public Mono delete(Long id) { - return bookRepository.deleteById(id); - } - - @Override - public Mono findById(Long id) { - return bookRepository.findById(id); - } -} diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/impl/CityServiceImpl.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/impl/CityServiceImpl.java new file mode 100644 index 00000000..d9e1059a --- /dev/null +++ b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/service/impl/CityServiceImpl.java @@ -0,0 +1,45 @@ +package demo.springboot.service.impl; + +import demo.springboot.dao.CityRepository; +import demo.springboot.domain.City; +import demo.springboot.service.CityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Component +public class CityServiceImpl implements CityService { + + private final CityRepository cityRepository; + + @Autowired + public CityServiceImpl(CityRepository cityRepository) { + this.cityRepository = cityRepository; + } + + @Override + public Flux findAll() { + return cityRepository.findAll(); + } + + @Override + public Mono insertByCity(City city) { + return cityRepository.save(city); + } + + @Override + public Mono update(City city) { + return cityRepository.save(city); + } + + @Override + public Mono delete(Long id) { + return cityRepository.deleteById(id); + } + + @Override + public Mono findById(Long id) { + return cityRepository.findById(id); + } +} diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/web/BookController.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/web/BookController.java deleted file mode 100644 index 75909745..00000000 --- a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/web/BookController.java +++ /dev/null @@ -1,89 +0,0 @@ -package demo.springboot.web; - -import demo.springboot.domain.Book; -import demo.springboot.service.BookService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -/** - * Book 控制层 - *

- * Created by bysocket - */ -@Controller -@RequestMapping(value = "/book") -public class BookController { - - private static final String BOOK_FORM_PATH_NAME = "bookForm"; - private static final String BOOK_LIST_PATH_NAME = "bookList"; - private static final String REDIRECT_TO_BOOK_URL = "redirect:/book"; - - @Autowired - BookService bookService; - - /** - * 获取 Book 列表 - * 处理 "/book" 的 GET 请求,用来获取 Book 列表 - */ - @RequestMapping(method = RequestMethod.GET) - public String getBookList(final Model model) { - model.addAttribute("bookList", bookService.findAll()); - return BOOK_LIST_PATH_NAME; - } - - /** - * 获取创建 Book 表单 - */ - @RequestMapping(value = "/create", method = RequestMethod.GET) - public String createBookForm(final Model model) { - model.addAttribute("book", new Book()); - model.addAttribute("action", "create"); - return BOOK_FORM_PATH_NAME; - } - - /** - * 创建 Book - * 处理 "/book/create" 的 POST 请求,用来新建 Book 信息 - * 通过 @ModelAttribute 绑定表单实体参数,也通过 @RequestParam 传递参数 - */ - @RequestMapping(value = "/create", method = RequestMethod.POST) - public String postBook(@ModelAttribute Book book) { - bookService.insertByBook(book); - return REDIRECT_TO_BOOK_URL; - } - - /** - * 获取更新 Book 表单 - * 处理 "/book/update/{id}" 的 GET 请求,通过 URL 中的 id 值获取 Book 信息 - * URL 中的 id ,通过 @PathVariable 绑定参数 - */ - @RequestMapping(value = "/update/{id}", method = RequestMethod.GET) - public String getUser(@PathVariable Long id, final Model model) { - model.addAttribute("book", bookService.findById(id)); - model.addAttribute("action", "update"); - return BOOK_FORM_PATH_NAME; - } - - /** - * 更新 Book - * 处理 "/update" 的 PUT 请求,用来更新 Book 信息 - */ - @RequestMapping(value = "/update", method = RequestMethod.POST) - public String putBook(@ModelAttribute Book book) { - bookService.update(book); - return REDIRECT_TO_BOOK_URL; - } - - /** - * 删除 Book - * 处理 "/book/{id}" 的 GET 请求,用来删除 Book 信息 - */ - @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) - public String deleteBook(@PathVariable Long id) { - bookService.delete(id); - return REDIRECT_TO_BOOK_URL; - } - -} diff --git a/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/web/CityController.java b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/web/CityController.java new file mode 100644 index 00000000..5028c7f5 --- /dev/null +++ b/springboot-webflux-10-book-manage-sys/src/main/java/demo/springboot/web/CityController.java @@ -0,0 +1,71 @@ +package demo.springboot.web; + +import demo.springboot.domain.City; +import demo.springboot.service.CityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import reactor.core.publisher.Mono; + +import java.awt.print.Book; + +/** + * city 控制层 + *

+ * Created by bysocket + */ +@Controller +@RequestMapping(value = "/city") +public class CityController { + + private static final String CITY_FORM_PATH_NAME = "cityForm"; + private static final String CITY_LIST_PATH_NAME = "cityList"; + private static final String REDIRECT_TO_CITY_URL = "redirect:/city"; + + @Autowired + CityService cityService; + + @RequestMapping(method = RequestMethod.GET) + public String getCityList(final Model model) { + model.addAttribute("cityList", cityService.findAll()); + return CITY_LIST_PATH_NAME; + } + + @RequestMapping(value = "/create", method = RequestMethod.GET) + public String createCityForm(final Model model) { + model.addAttribute("city", new City()); + model.addAttribute("action", "create"); + return CITY_FORM_PATH_NAME; + } + + @RequestMapping(value = "/create", method = RequestMethod.POST) + public String postCity(@ModelAttribute City city) { + cityService.insertByCity(city); + return REDIRECT_TO_CITY_URL; + } + + @RequestMapping(value = "/update/{id}", method = RequestMethod.GET) + public String getCity(@PathVariable Long id, final Model model) { + final Mono city = cityService.findById(id); + model.addAttribute("city", city); + model.addAttribute("action", "update"); + return CITY_FORM_PATH_NAME; + } + + @RequestMapping(value = "/update", method = RequestMethod.POST) + public String putBook(@ModelAttribute City city) { + cityService.update(city); + return REDIRECT_TO_CITY_URL; + } + + @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) + public String deleteCity(@PathVariable Long id) { + cityService.delete(id); + return CITY_LIST_PATH_NAME; + } + +} diff --git a/springboot-webflux-10-book-manage-sys/src/main/resources/templates/bookForm.html b/springboot-webflux-10-book-manage-sys/src/main/resources/templates/bookForm.html deleted file mode 100644 index 9a893eb6..00000000 --- a/springboot-webflux-10-book-manage-sys/src/main/resources/templates/bookForm.html +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - - - 书籍管理 - - - -

- - - 书籍管理 - - -
- - - -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
-
-    - -
-
-
-
- - diff --git a/springboot-webflux-10-book-manage-sys/src/main/resources/templates/cityForm.html b/springboot-webflux-10-book-manage-sys/src/main/resources/templates/cityForm.html new file mode 100644 index 00000000..e4732a36 --- /dev/null +++ b/springboot-webflux-10-book-manage-sys/src/main/resources/templates/cityForm.html @@ -0,0 +1,61 @@ + + + + + + + + + 城市管理 + + + +
+ + + 城市管理 + + +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+
+    + +
+
+
+
+ + diff --git a/springboot-webflux-10-book-manage-sys/src/main/resources/templates/bookList.html b/springboot-webflux-10-book-manage-sys/src/main/resources/templates/cityList.html similarity index 50% rename from springboot-webflux-10-book-manage-sys/src/main/resources/templates/bookList.html rename to springboot-webflux-10-book-manage-sys/src/main/resources/templates/cityList.html index e78de209..da764dfb 100644 --- a/springboot-webflux-10-book-manage-sys/src/main/resources/templates/bookList.html +++ b/springboot-webflux-10-book-manage-sys/src/main/resources/templates/cityList.html @@ -6,7 +6,7 @@ - 书籍列表 + 城市列表 @@ -15,29 +15,30 @@ - 书籍列表 + 城市列表 - - - - + + + + - - - - - - + + + + + + +
书籍编号书名作者简介城市编号城市名称描述省份编号 管理
删除
删除
- +