Spring Boot实战
最新书摘:
-
stephansun2016-09-30@Controller@RequestMapping("/readingList")public class ReadingListController { private static final String reader = "craig"; private ReadingListRepository readingListRepository;@Autowiredpublic ReadingListController(ReadingListRepository readingListRepository) {this.readingListRepository = readingListRepository;}@RequestMapping(method=RequestMethod.GET)public String readersBooks(Model model) {List<Book> readingList = readingListRepository.findByReader(reader);if (readingList != null) {model.addAttribute("books", readingList);}return "readingList";}@RequestMapping(method=RequestMethod.POST)public String addToReadingList(Book book) {book.setReader(reader);readingListRepository.save(book);return "redirect:/readingList";}}
-
stephansun2016-09-30Listing 2.6 A Spring MVC controller that fronts the reading list application package readinglist; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import java.util.List; @Controller @RequestMapping("/") public class ReadingListController { private ReadingListRepository readingListRepository; @Autowired public ReadingListController(...