Thymeleaf not seeing objcet added to model with model.addObject()
تبليغيرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.
I’m haveing problems with thymeleaf in Java project because it doesn’t see any objects I’m adding to my models.
Here’s my GET mapping:
@GetMapping(USER_PATH)
public ModelAndView getUserOffersView(){
ModelAndView model = new ModelAndView(“/panel/user/offer-list”);
List<Firearm> firearmList = firearmService.findAllByUserId(userService.findLogged().get().getUserId());
model.addObject(“firearmList”, firearmList);
return model;
}
And that’s HTML where I’M tryign to access it:
<div class=”row”>
<div class=”col-md-4″ th:each=”offer : ${firearmList}”>
<div class=”card mb-4 product-wap rounded-0″ style=”max-width: 250px; max-height: 500px”>
<div class=”card rounded-0″>
<img class=”card-img rounded-0 img-fluid” src=”/img/shop_01.jpg”>
<div class=”card-img-overlay rounded-0 product-overlay d-flex align-items-center justify-content-center”>
<ul class=”list-unstyled”>
<li><a class=”btn btn-success text-white” href=”shop-single.html”><i class=”far fa-heart”></i></a></li>
<li><a class=”btn btn-success text-white mt-2″ href=”shop-single.html”><i class=”far fa-eye”></i></a></li>
<li><a class=”btn btn-success text-white mt-2″ href=”shop-single.html”><i class=”fas fa-cart-plus”></i></a></li>
</ul>
</div>
</div>
<div class=”card-body”>
<a href=”shop-single.html” class=”h3 text-decoration-none” th:text=”${offer.title}”></a>
<ul class=”w-100 list-unstyled d-flex justify-content-between mb-0″>
<li></li>
</ul>
<p class=”text-center mb-0″ th:text=”${offer.price}”></p>
</div>
</div>
</div>
</div>
For some reason thymeleaf doesn’t recongize any object, but sometimes if I type the object’s value I’m trying to access, eg offer.price as shown here it DOES SHOW in the browser, so it can access the data, but it does not see the object, which makes coding incredibly painful. I’m not sure if that’s related, but my controllers cannot find any views in the project: PIC REL HERE.
My pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!– lookup parent from repository –>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>2.16.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.6.9.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.3.21</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
أضف إجابة