0
votes

i am a beginner of Spring boot. i made the simple crud application but i don't any errors while compiling the project but i couln't see the output in the browswer. i don't know why.

    .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.4.RELEASE)

only display like this couln't see the output in the browswer. i don't know why.

Employee Controller look like this

@Controller
public class employeeController {   
    @Autowired
    private employeeservice service;    
    @RequestMapping("/")
    public String viewHomePage(Model model) {
        List<employee> listemployee = service.listAll();
        model.addAttribute("listemployee", listemployee);
        
        return "index";
    }   
    @RequestMapping("/new")
    public String showNewEmployeePage(Model model) {
        employee emp = new employee();
        model.addAttribute("employee", emp);
        
        return "new_employee";
    }   

Index.html

<tbody>
    <tr th:each="employee : ${listemployee}">
        <td th:text="${employee.id}">Employee ID</td>
        <td th:text="${employee.firstname}">FirstName</td>
        <td th:text="${employee.brand}">LastName</td>

        <td>
            <a th:href="@{'/edit/' + ${employee.id}}">Edit</a>
            &nbsp;&nbsp;&nbsp;
            <a th:href="@{'/delete/' + ${employee.id}}">Delete</a>
        </td>
    </tr>
</tbody>

enter image description here

2020-09-18 13:05:15.081  INFO 10660 --- [           main] com.example.gov.GovApplication           : Starting GovApplication on kobinath-pc with PID 10660 (C:\Users\kobinath\eclipse-workspace1s\gov.zip_expanded\gov\target\classes started by kobinath in C:\Users\kobinath\eclipse-workspace1s\gov.zip_expanded\gov)
2020-09-18 13:05:15.085  INFO 10660 --- [           main] com.example.gov.GovApplication           : No active profile set, falling back to default profiles: default
2020-09-18 13:05:15.993  INFO 10660 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-09-18 13:05:16.082  INFO 10660 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 73ms. Found 1 JPA repository interfaces.
2020-09-18 13:05:17.018  INFO 10660 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9040 (http)
2020-09-18 13:05:17.031  INFO 10660 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-09-18 13:05:17.031  INFO 10660 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-09-18 13:05:17.184  INFO 10660 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-09-18 13:05:17.184  INFO 10660 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2015 ms
2020-09-18 13:05:17.468  INFO 10660 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-09-18 13:05:17.532  INFO 10660 --- [         task-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-09-18 13:05:17.643  INFO 10660 --- [         task-1] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.21.Final
2020-09-18 13:05:18.072  INFO 10660 --- [         task-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-09-18 13:05:18.094  INFO 10660 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2020-09-18 13:05:18.301  INFO 10660 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-09-18 13:05:18.410  INFO 10660 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9040 (http) with context path ''
2020-09-18 13:05:18.412  INFO 10660 --- [           main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-09-18 13:05:18.615  INFO 10660 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-09-18 13:05:18.657  INFO 10660 --- [         task-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect
2020-09-18 13:05:19.546  INFO 10660 --- [         task-1] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-09-18 13:05:19.558  INFO 10660 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-09-18 13:05:19.836  INFO 10660 --- [           main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-09-18 13:05:19.849  INFO 10660 --- [           main] com.example.gov.GovApplication           : Started GovApplication in 5.297 seconds (JVM running for 5.845)

porm.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>gov</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>gov</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <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.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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

spring.jpa.hibernate.ddl-auto=none

spring.datasource.url=jdbc:mysql://localhost:3306/gov?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC server.error.whitelabel.enabled=false

server.port=8030
spring.datasource.username=root
spring.datasource.password=
logging.level.root=WARN
spring.jpa.open-in-view=false
1
Your code looks fine . This should work . Did you add logger related properties to your application.properties file ?Ajit Soman
application.properties i added above pls check sirtuts fun
remove this line logging.level.root=WARN from your application.properties file . Because of this DEBUG and INFO level logs are not visible for youAjit Soman
after remove that i got message i attached above pls check is there any errorstuts fun
There are no errors in your logsAjit Soman

1 Answers

0
votes

I believe that you make some typo mistakes between Enity and template. I hope this repo can help

https://github.com/toannh0104/spring-boot-test

I prefer you write code following java standard then It's more readable

https://imgur.com/wrTWBp9

https://imgur.com/ct7k2uI

https://imgur.com/iw5bS0c