@RequestMapping("/book/**") @Controller public class BookController { @RequestMapping(value = "/book", method = RequestMethod.POST) public String create( @ModelAttribute("bookCommand") final BookCommand bookCommand) { Book book = createBookFromBookCommand(bookCommand); return "redirect:/book/" + book.getId(); } @RequestMapping(value = "/book/form", method = RequestMethod.GET) public String createForm(final ModelMap modelMap) { modelMap.addAttribute("all", "what you need"); return "book/create"; //book/create.jsp } }
@Transactional(propagation = Propagation.REQUIRED, readOnly = false) public void addArticleToBook(Article article, Book book) { articleDao.saveArticle(article); bookDao.addArticle(article, book.getId()); }
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { Book item = (Book) parent.getItemAtPosition(position); int selected_id = item.getId(); Log.i("selected id:--->", selected_id+""); } });
Observable .from(books) .map(new Func1<Book, Book>() { @Override public Book call(Book b) { if (book.getId().equals(b.getId())) return book; return b; } }) .toList() .subscribe();
private static void Book searchBook(int book_id) { if(head == null) return null; Book iterator = head; while(iterator != null){ if(iterator.getId() == book_id){ return iterator; } iterator = iterator.next; } return null; }
Book testBook = itemList.get(itemList.size()-1); Log.i("ID of recently inserted book is " + testBook.getId());
Map<String, Book> booksById = new HashMap<String, Book>(list.size()); for (Object o : list) { Book book = (Book) o; booksById.put(book.getId(), book); }
// Get the ids as a List so we can use indexOf() final List<String> ids = Arrays.asList(idList); // After executing this single line, list will be sorted in idList order: Collections.sort(list, new Comparator<Book>() { public int compare(Book o1, Book o2) { return ids.indexOf(o1.getId()) - ids.indexOf(o2.getId()); } });
HashMap<Integer, Book> bookHash = new HashMap<Integer, Book>(); for (Book book : listOfBooks) { bookHash.put(book.getId(), book); }
@Entity public class Book implements Identifiable<Long> { @Id @GeneratedValue private Long id; private String title; @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Book)) return false; Book book = (Book) o; return Objects.equals(getId(), book.getId()); } @Override public int hashCode() { return 31; } //Getters and setters omitted for brevity }
@Entity public class Book implements Identifiable<Long> { @Id @GeneratedValue private Long id; private String title; @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Book)) return false; Book book = (Book) o; return getId() != null && Objects.equals(getId(), book.getId()); } @Override public int hashCode() { return 31; } //Getters and setters omitted for brevity }
List list = new ArrayList<>(); for(Book c:GlobalObjects.bookList){ if(c.getBookName().startsWith(name)){ jsonObjec=new JSONObject(); jsonObjec.put("label",c.getBookName()); jsonObjec.put("value", c.getId()); list.add(jsonObjec);//java.util.ConcurrentModificationException } } jsonArr.addAll(list);
@Override public void serialize(Author value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.DEFAULT_VIEW_INCLUSION, false); mapper.setSerializationConfig(mapper.getSerializationConfig().withView(SummaryView.class)); jgen.writeStartObject(); for (Book book : value.getBestFiveBooksOfAllTime()) { jgen.writeFieldName(book.getId().toString()); mapper.writeValue(jgen, book); } jgen.writeEndObject(); }
Iterator<Book> iterator = bookList.iterator(); while(iterator.hasNext()){ Book c = iterator.next(); if(c.getBookName().startsWith(name)){ jsonObjec=new JSONObject(); jsonObjec.put("label",c.getBookName()); jsonObjec.put("value", c.getId()); jsonArr.add(jsonObjec); } }
@Override public void add(Book book) { if (getBook(book.getId()) != null) { LOG.info("Ignoring book {} as it already exists.", book.getId()); return; } for (Format fomat : book.getFormats()) { em.persist(fomat); } persistSubjects(book); em.persist(book); if ("error1".equals(book.getTitle())) { throw new RuntimeException("Test for error handling. Should cause tx rollback"); } }
public void useWebClient() { System.out.println("Using WebClient to get the book with id 123"); WebClient client = WebClient.create("http://localhost:" + port + "/services/bookstore/"); Book book = client.post(new Book("HTTP"), Book.class); System.out.println(book.getId() + ":" + book.getName()); } public void useJMSClient() throws Exception { System.out.println("Getting the book with id 123 over JMS"); getBookOverJMS(); System.out.println("Adding a new book over JMS"); addGetBookOverJMS(new Book("JMS Transport")); System.out.println("Adding a new book over JMS Oneway"); addGetOnewayBookOverJMS(); System.out.println("Adding a new book over HTTP Oneway, " + " and getting it back over JMS"); addOnewayOverHttpGetOverJMS(); }
@GET public Collection<Book> getBooks() { List<Book> outBooks = new ArrayList<>(); for (Book book : bookRepo.getBooks()) { Book outBook = new Book(); outBook.setId(book.getId()); outBook.setTitle(book.getTitle()); outBook.setCreator(book.getCreator()); outBooks.add(outBook); } return outBooks; }