1

I am extracting single employee to create employee dashboard page using @RequestParam annotation. I am able to get object data and able to log it and able to pass it to html page, but when view is called it is unable to render any styling. All content displays as plain html text.

Below is my model

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")

public class Employee {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    
    private String firstname;
    private String middlename;
    private String lastname;
    private String familyname;
    private String nationalityid;
    private String gender;
    private String fatherfirstname;
    private String fatherlastname;
    
    @ManyToOne
    @JoinColumn(name="jobtitleid", insertable=false, updatable=false)
    private JobTitle jobtitle;
    private Integer jobtitleid;
    
    @ManyToOne
    @JoinColumn(name="departmentid", insertable=false, updatable=false)
    private Department department;
    private Integer departmentid;
    
    
    private String familyStatus;
    
    @DateTimeFormat(pattern = "yyyy-MM-dd") 
    private Date hireDate;
    
    @DateTimeFormat(pattern = "yyyy-MM-dd") 
    private Date dateofbirth;
    private String address;

}

This is method which is passing single employee data to view employee**

@RequestMapping(value="/employees/getEmployeeById", method= {RequestMethod.GET})
          public String getEmpById(@RequestParam Integer id, Model model) {
              Employee employee = employeeService.findById(id).get();
              model.addAttribute(employee);
              System.out.println(employee);
              return "employee"; 
          }

Data is getting displayed in view page ("employee")

Also it is being displayed in log but when the link http://localhost:8080/employees/getEmployeeById/?id=1 navigates to view no styling works. Bootstrap also does not work. I am display data as plain html but styling doesn't work.

image showing data in table

1
  • You should debug this issue in browser's network tab whether css files path is correct or not. Commented Jun 7, 2021 at 6:54

1 Answer 1

2

Use Annotation @Controller on the above of @RequestMapping

Sign up to request clarification or add additional context in comments.

5 Comments

then also use @ResponseBody annotation
I am not creating a REST Api. Actually i am using thymleaf with spring boot.
stackoverflow.com/questions/47191324/… then maybe it helpful for you.
All content is already in static folder. everything works fine with other views. e.g. when i get list of all employees on "/employees" view. All styling works. but when navigated to above URL created using @RequestParam data is passed to view and i can show it in view but styling doesn't work. Even i copied html pages from other views and tried. Same issue. it is only raw html.
i was able to fix it by adding "/" in start of all static sources paths. e.g. <link href="css/bootstrap.min.css" rel="stylesheet"> to <link href="/css/bootstrap.min.css" rel="stylesheet">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.