Загрузка...

Spring boot project error

Thread in Frontend created by Wraper May 19, 2020. 125 views

  1. Wraper
    Wraper Topic starter May 19, 2020 0 Dec 18, 2019
    An error happened during template parsing
    Сайт продажи книг, по кнопке добавляются в таблицу ордерс, не могу сделать так чтобы в таблице ордерс показывало имя, еррор блят
    если че, айди показывает а нейм чет не хочет
    вот хтмл:
    <tr>

    <th>Book Id</th>
    <th>Book Name</th>
    <th>Book Price</th>
    <th>Full</th>
    </tr>
    <tr th:each="book:${objList}" >
    <td style="color:black" th:text=${book}></td>
    <td style="color:black"th:text=${book?.name}></td>
    <td style="color:black"th:text=${book?.price}></td>


    </tr>
    controller:
    package az.malishis.controller;

    import java.io.IOException;

    import java.time.Duration;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;
    import java.util.Optional;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.core.io.Resource;
    import org.springframework.http.MediaType;
    import org.springframework.http.ResponseEntity;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.multipart.MultipartFile;

    import az.malishis.DTO.BookDTO;
    import az.malishis.model.Author;
    import az.malishis.model.Book;
    //import az.malishis.model.Product;
    import az.malishis.model.Book;
    import az.malishis.repository.AuthorRepository;
    import az.malishis.repository.BookRepository;
    import az.malishis.service.BookService;
    import az.malishis.service.FileService;
    //import az.malishis.service.ProductService;

    contrOller_inactive992182
    public class FirstController {
    @Autowired
    public BookRepository bookRepo;
    @Autowired
    AuthorRepository authorRepository;
    @Autowired
    BookService bookService;
    @Autowired
    FileService fs;
    // @Autowired
    // ProductService productService;

    public static List<Book> Arrlist = new ArrayList<Book>();

    @GetMapping("/all")
    public String showList(Model model) {
    model.addAttribute("objList", bookRepo.findAll());
    return "all";
    }

    @GetMapping("/{id}/")
    public String showOne(@PathVariable("id") Integer id, Model model) {
    Optional<Book> optionalBook = bookRepo.findById(id);
    return "all";
    }

    @GetMapping("/")
    public String books(Model model) {
    model.addAttribute("users", bookRepo.findAll());
    return "redirect:/books";

    }

    @GetMapping("/books")
    public String books1(Model model) {
    Book book = new Book();
    model.addAttribute("books", bookRepo.findAll());
    return "Book";

    }


    @GetMapping("full/{id}/")
    public String getPath(@PathVariable("id") Integer id, Model model) {
    Optional<Book> Fulllist = bookRepo.findById(id);
    Book book = Fulllist.get();
    model.addAttribute("obj", book);
    return "fulls";
    }

    @GetMapping("/addbook")
    public String bookForm(Model model) {
    model.addAttribute("aList", authorRepository.findAll());
    model.addAttribute("book", new Book());
    return "bookad";
    }
    @GetMapping("/addauthor")
    public String addauthor(Model model) {
    model.addAttribute("author", new Author());
    return "authorad";
    }

    @PostMapping("/addbook")
    public String bookSubmit(@RequestParam("file") MultipartFile file,
    @RequestParam(value = "id", defaultValue = "1") Integer id, Book book) throws IOException {
    System.out.print(book.getId() + " " + book.getName());
    fs.saveFile(file, book);
    return "redirect:/books";
    }
    @PostMapping("/addauthor")
    public String authorSubmit(@RequestParam(value = "id", defaultValue = "1") Integer id, Author author) throws IOException {
    System.out.print(author.getId() + " " + author.getName());
    authorRepository.save(author);
    return "redirect:/books";
    }

    @GetMapping(value = "/install/{file:.+}", produces = MediaType.ALL_VALUE)
    public @ResponseBody ResponseEntity<Resource> download(@PathVariable("file") String filename) {
    Resource file = fs.loadAsResource(filename);

    return ResponseEntity.ok().body(file);
    }

    @GetMapping("/other/{id}/")
    public String showOneOher(@PathVariable("id") Book book, Model model) {
    model.addAttribute("obj", book);
    return "Book";
    }

    @PostMapping("/post")
    @ResponseBody
    public String postBook(@RequestParam("id") String id) {
    return "POST ID: " + id;
    }

    @GetMapping("/post")
    @ResponseBody
    public String getBook(@RequestParam("id") String id) {
    return "GET ID: " + id;
    }

    // @GetMapping("/add2db")
    // @ResponseBody
    // public String addBookToDB() {
    // Book book = new Book(98, "buks", new Date(), true, "xd");
    // bookRepo.save(book);
    // return "ok";
    // }

    // @GetMapping("/add2db")
    // @ResponseBody
    // public String addBookDTOPage(BookDTO book, Model model) {
    // model.addAttribute("obj", new BookDTO(44, "new book", true, "comics"));
    // return "bookad";
    // }

    @PostMapping("/add2db")
    @ResponseBody
    public String addBookDTO(BookDTO bookDTO, Model model) {
    model.addAttribute("info", "added succesfully!");
    bookService.saveBookDTO(bookDTO);
    // bookRepo.save(book);
    return "ok";
    }

    @GetMapping("/addviaservice")
    @ResponseBody
    public String addBookViaService() {
    Book book = new Book(99, "buk", new Date(), false, "4 nochi");
    boolean result = bookService.saveBook(book);
    return "result is: " + result;
    }

    @GetMapping("/addrel")
    @ResponseBody
    public String addBookToDb2() {
    Author author = new Author();
    authorRepository.save(author);
    author.setId(1);
    Book book = new Book(11, "buk", new Date(), false, "EXSEPTION");
    book.setAuthor(author);
    bookRepo.save(book);
    return "add relet";
    }
    //
    // @RequestMapping(value = "/addProduct/{id}", method = RequestMethod.GET)
    // public String addProduct(@PathVariable("id") Integer id) {
    // Product product = bookService.getProductById(id);
    // bookService.addProductToBasket(product, 1);
    // return "redirect:/";
    // }
    //
    // @RequestMapping(value = "/")
    // public String index(Model model, Model mode1) {
    // model.addAttribute("listProduct", bookService.listProduct());
    // mode1.addAttribute("productInBasket", bookService.getBasket());
    // return "index";
    // }

    }
    неадекват не писать
     
  2. Yoshino404
    Yoshino404 May 19, 2020 Эпоха Гуттенберга сменилась эпохой Цукерберга 1154 Nov 10, 2018
    Wraper, ты посмотри лучше, тут есть кнопка (код)
    Туда запихни этот высер
     
    1. Wraper Topic starter
      Yoshino404, я хз как это делать, и не оч важно
Loading...
Top