Код: Выделить всё
@Controller
@RequestMapping("/products")
public class ProductsController {
@Autowired
private ProductsRepository repo;
@GetMapping({"", "/"})
public String showProductList(Model model) {
List
products = repo.findAll(Sort.by(Sort.Direction.DESC, "id"));
model.addAttribute("products", products);
return "products/index";
}
}
Код: Выделить всё
//properties
spring.application.name=beststore
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/beststore
spring.datasource.username=root
spring.datasource.password=9874156R
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
Код: Выделить всё
org.springframework.boot
[url=/products]Products[/url]
Код: Выделить всё
resources/templates/products/index.html
Products
[url=/products/create]Create Product[/url]
ID
Name
Brand
Category
Price
Image
Create At
Action
[url=@{/products/edit(id=${product.id})}]Edit[/url]
[url=@{/products/delete(id=${product.id})}]Delete[/url]
Страница ошибки Whitelabel
Это приложение не имеет явного сопоставления для /error, поэтому вы видите это запасной вариант.
Ср, 15 января, 13:53:26 AZT 2025
Произошла непредвиденная ошибка (тип=Внутренняя ошибка сервера, статус=500).
Произошла ошибка во время анализа шаблона (шаблон: «ресурс пути к классу [templates/products/index.html]»)
org.thymeleaf.Exceptions.TemplateInputException: произошла ошибка во время анализа шаблона (шаблон: «ресурс пути к классу [templates/products/index.html]»)
Причина: : org.attoparser.ParseException: исключение при оценке выражения SpringEL: «product.id» (шаблон: «products/index» — строка 31, столбец 17) в org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) по адресу org.attoparser.MarkupParser.parse(MarkupParser.java:257) по адресу org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ... еще 48
Вызвано: org.thymeleaf.Exceptions.TemplateProcessingException: Исключение при оценке выражения SpringEL: «product.id» (шаблон: «products/index» — строка 31, столбец 17)
Вызвано: org.springframework.expression.spel.SpelEvaluationException: EL1008E: свойство или поле «id» не найдено в объекте типа «com.example.beststore.Model». Продукт» — возможно, он не общедоступен или недействителен?
Подробнее здесь: https://stackoverflow.com/questions/793 ... te-parsing
Мобильная версия