Reputation: 295
I've just created a very basic Spring app using Thymeleaf, and I have no idea why it's not working. I can't even display my <h1>
tag.
I basically get everything displayed but what I need to be displayed via Thymeleaf. The thing is I've used it before and it worked just fine. I have no idea what's wrong here and I've literaly spent the whole day looking for the solution.
I tried to upgrade my Java JDK, doesn't work (not even sure it has anything to do with it), currently using STS 4, I also tried on Netbeans 11, same result. I've added all the Thymeleaf dependencies that exist to my pom.xml
, and I just ran out of ideas. Even in my console log I don't get anything, no exception, no warning, just nothing.
I'm aiming to program something a bit complex, so if I can't even start with such a basic stuff, I won't go that far.
Hopefully someone will help me find the solution cause I just don't know what to do anymore.
NB: I'm using Ubuntu 18.04
The dependencies in my pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<type>pom</type>
<version>3.13.0</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.9.RELEASE</version>
</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>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
My Controller :
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.semweb.bikeproject.model.Station;
@Controller
public class BikeController {
private FusekiService fusekiService;
@RequestMapping("/index")
public String bike(Model model) {
model.addAttribute("top", "TOP TOP MANI");
return "index";
}
}
my index.html template
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<meta charset="UTF-8">
<body>
<h1 th:text="${top}"></h1>
<div id="googleMap" style="width:100%;height:700px;">
</div>
<form>
<input type="button" value="Click me" onclick="msg()">
</form>
<script>
var mapProp;
var map;
function myMap() {
mapProp= {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
};
map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
function msg() {
map.setCenter({lat: -34, lng: 151});
map.setZoom(12);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSallback=myMap"></script>
</body>
</html>
Upvotes: 4
Views: 6018
Reputation: 1775
Here is a workaround:
@Controller
public class BikeController {
private FusekiService fusekiService;
@RequestMapping("/index")
public ModelAndView bike() {
ModelAndView modelAndView = new ModelAndView("index");
modelAndView.addObject("top", "TOP TOP MANI");
//...
return modelAndView;
}
}
This works perfectly...
Upvotes: 2
Reputation: 552
You don't need to include the Thymeleaf dependencies separately if you are using the Spring Boot starter for it. All necessary dependencies on compatible versions are already included in the Thymeleaf starter. I would first try removing these, because the rest of your code seems fine at first sight.
Upvotes: 0