Can't pass an object from one Thymeleaf view to another Thymeleaf view - spring

I'm new to Spring, and I'm working on a Spring MVC + Thymeleaf application that tracks personal expenses. I have a page that shows the list of expenses, and upon clicking "Update" on any given expense, it would show a pre-populated form, on another page, with that expense's information. The problem I'm having is that I want to pass that expense object forward to this second page, but since the data was already fetched from the database in my first page, I wouldn't want to fetch it again from my Spring Data JPA repository.
I think the unusual part of my objective is that I'm trying to pass the object like this:
Controller -> Thymeleaf -> Controller -> Thymeleaf
While the controller has sent an Expenses object to the list of expenses page, I'm trying to resend that same object (or just the one Expense, even better) back to the controller, so it would populate the model in my second form page.
My Expense entity:
package com.williampoletto.expensetracker.entity;
import java.time.LocalDate;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
#NoArgsConstructor
#AllArgsConstructor
#Getter
#Setter
#EqualsAndHashCode(of= "id")
#ToString(exclude="categories")
#Entity
#Table
public class Expense {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY )
private int id;
#NotBlank
private String description;
#NotNull
private double value;
#NotNull
private LocalDate date;
private String note;
#ManyToOne
private User user;
#ManyToMany(cascade=CascadeType.PERSIST)
#JoinTable(
name="expense_category",
joinColumns=#JoinColumn(name="expense_id"),
inverseJoinColumns=#JoinColumn(name="category_id"))
private Set<Category> categories;
public void addCategory(Category category) {
categories.add(category);
}
public void removeCategory(Category category) {
categories.remove(category);
}
public Expense(int id, #NotBlank String description, #NotNull double value, #NotNull LocalDate date,
String note, Set<Category> categories) {
super();
this.id = id;
this.description = description;
this.value = value;
this.date = date;
this.note = note;
this.categories = categories;
}
}
My thymeleaf table:
<table class="table table-bordered table-striped">
<thead class="thead-dark">
<tr>
<th>Description</th>
<th>Value</th>
<th>Category</th>
<th>Note</th>
<th>Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr th:each="expense : ${expenses}">
<td th:text="${expense.description}"/>
<td th:text="${expense.value}"/>
<td>
<div th:each="category : ${expense.categories}">
<p th:text ="${category.name}"></p>
</div>
</td>
<td th:text="${expense.note}"/>
<td th:text="${expense.date}"/>
<td>
<form th:action="#{/expenses/showUpdateForm}" th:object="${expense}" method="POST">
<input type="text" name="expense" th:value="${expense.id}">
<input type="text" name="expenseDescription" th:value="${expense.description}">
<input type="text" name="expenseValue" th:value="${expense.value}">
<input type="text" name="expenseDate" th:value="${expense.date}">
<input type="text" name="expenseNote" th:value="${expense.note}">
<input type="text" name="expenseCategories" th:value="${expense.categories}">
<button th:if="${expense.user != null}" type="submit" class="btn btn-info btn-sm">Update</button>
</form>
<a th:href="#{/expenses/delete(expenseId=${expense.id})}"
class="btn btn-danger btn-sm"
onclick="if (!(confirm('Are you sure you want to delete this expense?'))) return false">Delete</a>
</td>
</tbody>
</table>
My /list and /showUpdateForm code for the controller:
#GetMapping("/list")
public String list(#AuthenticationPrincipal UserDetailsImpl userDetails, Model model) {
Set<Expense> expenses = expenseService.findAll(userDetails.getUserId());
model.addAttribute("expenses", expenses);
return "expenses";
}
#PostMapping("/showUpdateForm")
public String showFormForUpdate(#RequestParam("expenseId") int expenseId,
#RequestParam("expenseDescription") String expenseDescription,
#RequestParam("expenseValue") double expenseValue,
#RequestParam("expenseDate") String expenseDate,
#RequestParam("expenseNote") String expenseNote,
#RequestParam("expenseCategories") Set<Category> expenseCategories,
Model model) {
Expense expense = new Expense
(expenseId, expenseDescription, expenseValue, expenseDate, expenseNote, expenseCategories);
model.addAttribute("expense", expense);
return "/expense-form";
}
My final form page:
<form th:action="#{/expenses/save}" th:object="${expense}" method="POST">
<input type="hidden" th:field="*{id}">
<label>Description</label>
<input type="text" th:field="*{description}" class="form-control mb-4 col-4" placeholder="Description">
<label>Value</label>
<input type="text" th:field="*{value}" class="form-control mb-4 col-4" placeholder="Value">
<label>Date</label>
<input type="text" th:field="*{date}" class="form-control mb-4 col-4" placeholder="Date">
<label>Note</label>
<input type="text" th:field="*{note}" class="form-control mb-4 col-4" placeholder="Note">
<label>Categories</label>
<input type="hidden"
th:each="category : *{categories}"
th:value="${category.id}"
th:field="*{categories}"
th:text="${category.name}"/>
<button type="submit" class="btn btn-success col-2 mb-2">Save</button>
</form>
What I have tried:
Instead of sending an object, sending individual values as you can see in my thymeleaf table. The problem with this is that my Expense entity has a LocalDate, User (another entity) and Set attributes, so I had trouble converting these to an Expense object on the controller side. Ideally I would want to write something like this to simply pass on the object, but this example sends a toString:
<form th:action="#{/expenses/showUpdateForm}" th:object="${expense}" method="POST">
<input type="text" name="expense" th:value="${expense}">
</form>
Tried to use an argument to /showUpdateForm to hopefully get the expenses object from the model:
#RequestAttribute("expenses") Set<Expense> expenses
Tried to retrieve the object like this in /showUpdateForm, with the same intent as 2:
Set<Expense> expenses = (Set<Expense>) model.getAttribute("expenses");
Tried to use RedirectAttributes in the controller, which I saw can be useful for passing objects between controllers, but maybe not in my case:
#GetMapping("/showUpdateForm")
public String showFormForUpdate(Model model, RedirectAttributes attributes) {
attributes.addAttribute("expenses");
return "/expense-form";
}
Anyway, I have no idea how to achieve this, I would appreciate any light on the subject! I know that I can easily fix this by simply sending an id from view to controller, then I could perform a repository search of the object with that ID, but that would be cumbersome to the database since the data already exists and was fetched in the previous page.

Related

Insert multiple rows to MySQL with JPA

I am a newbie to spring boot. I have two entities: course1 and course2 with each having a field code, for course code. I have been able to generate select form fields due to entries on couse1 database table so that input to course2 will be selected. However, whenever I make a selection on the form and post, all the selected course codes will enter a single field on course2 database table instead of each entering a separate row. Hence, my problem is, I want to insert multiple rows into a database table using JPA. Following is what I did and will be grateful if any body helps
Course1 entity:
`
#NoArgsConstructor
#AllArgsConstructor
#Setter
#Getter
#Entity
#Table(name = "course_one")
public class CourseOne {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "course_one_id")
private Long courseOneId;
#Column(name = "course_code")
private String code;
#OneToOne(mappedBy = "courseOne")
private CourseTwo courseTwo;
`
Course1 entity contains more fields describing each course though.
Course2 entity:
`
#NoArgsConstructor
#AllArgsConstructor
#Setter
#Getter
#Entity
#Table(name="course_two")
public class CourseTwo{
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "course_two_id")
private Long courseTwoId;
private String code;
#OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
#JoinColumn(name = "course_one_id")
private CourseOne courseOne;
`
Course2 repository
`
public interface CourseTwoRepository extends CrudRepository<CourseTwo, Long> {
}
`
At the service layer, the method I used to insert into the database table for course2 entity is:
`
public List<CourseTwo> saveCourseTwo(CourseTwo courseTwo) {
return(List<CourseTwo>) courseTwoRepo.saveAll(List.of(courseTwo));
}
`
This is my form:
<form action="#" th:action="#{/saveCourseTwo}" th:object="${courseTwo}" method="post">
<div class="overflow-scroll" style="border: 2px; height:dashed; height:300px; width:800px">
<div class="table-responsive">
<table class="table table-sm table-striped table-hover" style="width: 100%">
<thead class="green white-text">
<tr>
<th>Select</th>
<th>Code</th>
<th>Title</th>
<th>Units</th>
</tr>
</thead>
<tbody>
<tr th:each="select : ${listCourseOne}">
<td><input type="hidden" th:value="${select.courseOneId}" name="courseOne"/></td>
<td><input type="checkbox" class="form-check-input" name="code" th:value="${select.code}" />
<td th:text="${select.code}"></td>
<td th:text="${select.title}"></td>
<td th:text="${select.units}"></td>
</tr>
</tbody>
</table>
</div>
</div>
<button type="submit" class="btn btn-success">Save</button>
</form>
However, the method inserts all the selected course codes into a single field. I will be happy if anyone helps.
I also tried to create wrapper multiple instances of CourseTwo as follows:
List<CourseTwo> lisOfCourse =new ArrayList<>(courseTwo);
List<CourseTwo> courseTwoList = new ArrayList<>();
for(int i=0; i<lisOfCourse.size(); i++){
CourseTwo courseTwo1 = new CourseTwo();
courseTwo1.setCourseTwoId(courseTwo1.courseTwoId());
courseTwo1.setCode(courseTwo1.getCode());
courseTwoList.add(courseTwo1);
}
return (List<CourseTwo>) courseTwoRepo.saveAll(courseTwoList);
However, I get the following error: No primary or single unique constructor found for interface java.util.List

How to send list of items from JSP back to Controller in Spring boot?

I'm trying to display list of questions on JSP page and using the check-box to select and submit them back to controller.
I can display them without any problem but when they're Posted back 'QuestionsListWrapper' is Null. Can someone point to me where I'm going wrong.
Entity Question
public class Questions implements Serializable {
#Id
#GeneratedValue
private Integer quesId;
#Transient
private boolean isSelected;
Wrapper class
public class QuestionsListWrapper {
private List<Questions> quesWrapperList;
public List<Questions> getQuesWrapperList() {
return quesWrapperList;
}
public void setQuesWrapperList(List<Questions> quesWrapperList) {
this.quesWrapperList = quesWrapperList;
}
Controller Get
#GetMapping("/group/{id}")
public String showForm(#PathVariable("id") Integer id, Model model) {
Assessments ass = as.getAssById(id);
List<Questions> qlist = qs.getQuesByAssessment(ass);
QuestionsListWrapper qlw = new QuestionsListWrapper();
qlw.setQuesWrapperList(qlist);
model.addAttribute("questions", qlw.getQuesWrapperList());
return "stuEssay";
Controller Post
#PostMapping("/saveSelectedQuestions")
//Here questions is null
public String saveSelectedQuestions(#ModelAttribute("questions") QuestionsListWrapper questions, Model model) {
List<Questions> selected = questions.getQuesWrapperList();
System.out.println(questions.toString());
System.out.println(questions.getQuesWrapperList());
return "redirect:/studentHome";
JSP
<form:form action="/saveSelectedQuestions" method="post" modelAttribute="questions">
<c:forEach items="${questions}" var="question" varStatus="count">
<input type="hidden" name="quesId" value="${question.quesId}">
<div class="form-group">
<textarea rows="3" >${question.quesText}</textarea>
<input type="checkbox" name="isSelected[${count.count}]"/>
</div>
</c:forEach><!-- End of question list -->
<div class="modal-footer">
<button type="submit" class="btn btn-primary" >Submit</button>
</div>
</form:form>

How Spring Boot understand on what exactly custom object is need to map fields from html?

In Spring boot application:
Here repo:
import org.springframework.data.repository.CrudRepository;
import myproject.eshop.model.User;
// Use JPQL
public interface UserRepository extends CrudRepository<User, Long> {
User findByUsername(String username);
}
Here controller:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import myproject.eshop.model.Role;
import myproject.eshop.model.User;
import myproject.eshop.repo.UserRepository;
import java.util.Collections;
#Controller
public class RegistrationController {
#Autowired
private UserRepository userRepository;
#GetMapping("/registration.html")
public String registration(Model model) {
logger.info("open_registration.html");
model.addAttribute("appName", appName);
return "registration.html";
}
#PostMapping("/registration.html")
public String registartionNewUser(User user, Model model, #RequestParam(name = "retypePassword", required = true) String retypePassword) {
logger.info("retypePassword = " + retypePassword + ", user = " + user);
if (user.getUsername().trim().isEmpty()
|| user.getPassword().trim().isEmpty()
) {
model.addAttribute("registrationError", "Аll fields are required!");
return "registration.html";
}
user.setActive(true);
user.setRoles(Collections.singleton(Role.USER));
User userFromDb = userRepository.findByUsername(user.getUsername());
if (userFromDb != null) {
model.addAttribute("registrationError", "User already exist!");
return "registration.html";
}
userRepository.save(user);
return "redirect:/login.html";
}
}
here template:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="${appName}">Template title</title>
<link th:href="#{/public/style.css}" rel="stylesheet"/>
</head>
<body>
<div id="container">
<h2 align="center">Registration new user</h2>
<form th:action="#{/registration.html}" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username" autofocus="autofocus"/>
<label for="password">Password</label>
<input type="password" id="password" name="password"/>
<label for="retypePassword">Retype password</label>
<input type="password" id="retypePassword" name="retypePassword"/>
<input id="submit" type="submit" value="Registration"/>
</form>
<p th:if="${registrationError}" th:text="${registrationError}" class="error"></p>
</div>
</body>
</html>
Here my custom object User:
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Set;
#Entity
#Table(name = "usr") // PostgreSQL not work with table "user"
public class User {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
#NotNull
private String username;
#NotNull
private String password;
#NotNull
private boolean active;
#NotNull
#ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER)
#CollectionTable(name = "user_role", joinColumns = #JoinColumn(name = "user_id"))
#Enumerated(EnumType.STRING)
private Set<Role> roles;
When open registration.html filled all fields and click submit button then call method registartionNewUser
And param user is correct filled (from form registration.html).
How Spring Boot link form registration.html with my customer object User ?
In registration.html no link to my customer object User
Basically you're implemented hibernate or jpa in backend which handle this things for you.
Notice that you column names are same as your name which you pass by html.
So that they accept the requested object get individual variable and create empty object of User class and place on exect match in User entity class and this way create User object.
For cross verification change it to capital or something it gives an 400 error.
This process is not that much easy as we discuss. You modify this as your way using javax library annotations.
For more detail this link,
https://howtodoinjava.com/hibernate-tutorials/
Have you tried make use of #ModelAttribute annotation which will map your custom made
object User to a model attribute and then exposes it to a web view.
<form th:action="#{/registration.html}" modelAttribute= "user" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username" path = "username"
autofocus="autofocus"/>
<label for="password">Password</label>
<input type="password" id="password" name="password" path = "password"/>
<label for="retypePassword">Retype password</label>
<input type="password" id="retypePassword" name="retypePassword"/>
<input id="submit" type="submit" value="Registration"/>
</form>
And then you bind it in the controller class:
#GetMapping( "/registration.html")
public String registration( #ModelAttribute("user") User user, Model model) {
logger.info("open_registration.html");
model.addAttribute("appName", appName);
return "registration.html";
}

Problem with passing changed subobject in SPRING application via Thymeleaf template

I am new in SPING and web developing.
I am developing the test task - quote book (without authorizing). I have two entities: Quote and Author. There is the code:
#Entity
#Table(name="authors")
public class Author {
#Id
#SequenceGenerator(name="author_id_seq", sequenceName="author_id_seq", allocationSize=1)
#GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "author_id_seq")
#Column(name = "id")
private long id;
#Column(name = "nick_name")
private String nickName;
public Author() {
}
public Author(long id, String nickName) {
this.id = id;
nickName = nickName;
}
/*
Getters and Setters
*/
}
Quote:
#Entity
#Table(name = "quotes")
public class Quote {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "quotes_id_seq")
#SequenceGenerator(name="quotes_id_seq", sequenceName="quotes_id_seq", allocationSize=1)
#Column(name = "id")
private long id;
#Column(name = "content")
private String content;
// #Temporal(TemporalType.DATE)
#Column(name = "date")
private LocalDate date;
#ManyToOne
#JoinColumn(name = "author")
private Author author;
public Quote() {
}
public Quote(long id, String content, LocalDate date, Author author) {
this.id = id;
this.content = content;
this.date = date;
this.author = author;
}
/*
Getters and Setters
*/
}
My Thymeleaf template contains form with two input fields(for quote.content and for quote.author.nickName) and select with existing authors. I want to see the behavior, when i fill input for author, content and if author is not existing in authors table, my application add the row in this table with specified by value from input nickName and generated id. But the problem is in getting unexpected result for me from Thymeleaf template. Template pass to controller the Quote object with author, which nickname is null instead of value from my input. There is thymeleaf template code of my form:
<form action="#" th:action="#{/newQuote}" th:object="${quote}" method="post">
<div class="form-row">
<div class="form-group col-md-3">
<label class="sr-only" for="inputNick">Nick Name</label>
<!--/*#thymesVar id="author" type="hello.entity.Author"*/-->
<input type="text" class="form-control" id="inputNick" th:field="*{author.nickName}"
placeholder="enter Nick Name">
</div>
<div class="form-group col-md-6">
<select id="nickNames">
<th:block th:each="author : ${allAuthors}">
<option th:text="${author.nickName}">Nick Name</option>
</th:block>
</select>
</div>
<div class="form-group col-md-12">
<label for="postContent">Your Quote:</label>
<input type="text" class="form-control" id="postContent" th:field="*{content}"
placeholder="quote text">
</div>
</div>
<div class="form-group col-md-2">
<input type="submit" value="Add Quote"/>
</div>
<div class="form-group col-md-2">
<input type="reset" value="Reset"/>
</div>
</form>
Controller methods:
#GetMapping("/newQuote")
public String showAuthors(Model model){
model.addAttribute("allAuthors",authorService.findAll());
model.addAttribute("quote", new Quote());
return "newQuote";
}
#PostMapping("/newQuote")
public String addQuote (#ModelAttribute Quote quote) {
quote.setDate(LocalDate.now());
quoteRepository.save(quote);
return "redirect:/";
I've tried:
to add Author object in GetMapping, pass it in newQuote template,
pass from it to PostMapping - no effect. Null in nickname.
to create and insert author object in quote object, pass to
template, pass to postmapping. no effect
I know that i can create DTO class with field nickname insteadof author field and convert it into my entity class in postmapping method of controller. But i think that it is "bad practice" way. I think, that i made wrong steps,may be, when tried to change author object and pass it from thymeleaf to controller. And also i suppose, that there is no way to realize this logic in this situation. i dont know where is the truth. Please, help me in finding it.
P.S: sorry for my bad english
So, the answer is asking how to add a quote and it's author at the same time. With a select approach is impossible, since our author doesn't exists. And simple way to achieve this, is changing your quote entity and adding #Cascade(CascadeType.PERSIST) to the author field in quote. This will automatically persist the author with your quote.
These would be the changes to your code that you would required to accomplish this.
Update
Since, the last solution didn't work, we will try sending an additional parameter to our controller, to avoid receiving a null, instead of the author's nickname.
Controller
#PostMapping("/newQuote")
public String addQuote (#ModelAttribute Quote quote,
#RequestParam("nickName") String nickName) {
// This will automatically persist your quote and it's author.
quote.setDate(LocalDate.now());
Author author = new Author();
author.setNickName(nickName);
quoteRepository.save(quote);
}
Quote Entity
#Entity
#Table(name = "quotes")
public class Quote {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "quotes_id_seq")
#SequenceGenerator(name="quotes_id_seq", sequenceName="quotes_id_seq", allocationSize=1)
#Column(name = "id")
private long id;
#Column(name = "content")
private String content;
#Column(name = "date")
private LocalDate date;
#ManyToOne
#Cascade(CascadeType.PERSIST)
#JoinColumn(name = "author")
private Author author;
// Getters and Setters
}
Important, make sure to notice that we are adding a new annotation #Cascade(CascadeType.PERSIST) to our author field.
HTML
Here we will simply remove the unnecessary select.
<form action="#" th:action="#{/newQuote}" th:object="${quote}" method="post">
<div class="form-row">
<div class="form-group col-md-3">
<label class="sr-only" for="inputNick">Nick Name</label>
<!--/*#thymesVar id="author" type="hello.entity.Author"*/-->
<input type="text" name="nickName" class="form-control" id="inputNick" placeholder="enter Nick Name"/>
</div>
<div class="form-group col-md-12">
<label for="postContent">Your Quote:</label>
<input type="text" class="form-control" id="postContent" th:field="*{content}" placeholder="quote text"/>
</div>
</div>
<div class="form-group col-md-2">
<input type="submit" value="Add Quote"/>
</div>
<div class="form-group col-md-2">
<input type="reset" value="Reset"/>
</div>
</form>

How to POST data using API in Postman

I am creating an API by using spring boot. Basically, this API does CRUD operations. And also I created a client that consumes my own API. At first I use Postman to POST data, it successfully insert data to the database and gives me 200 OK code. Then I created web page and I use my API as form action. Then I tried to insert data using the API. But, couldn't. Then I removed #RequestBody from the method and after that I was able to insert data. But the thing is now I can't insert data using Postman. When I try to insert data using Postman, it gives me 200 OK, but nothing insert to the database.
How can I Fix this ??
package com.kisalka.pacrestapi.controller;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.kisalka.pacrestapi.repository.ImRepository;
import com.kisalka.pacrestapi.model.ImModel;
#RestController
#RequestMapping("/api")
public class ImController {
#Autowired
private ImRepository TaskRepository;
#RequestMapping(method=RequestMethod.POST, value="/tasks")
public ImModel createNote(ImModel note) {
return TaskRepository.save(note);
}
}
My web page.
<form class="form-horizontal" method="POST" action="">
<div class="form-group">
<label class="control-label col-md-3">Project Name</label>
<div class="col-md-7">
<input type="text" class="form-control" name="pname" id="txtPname"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Developer Name</label>
<div class="col-md-7">
<input type="text" class="form-control" name="devname" id="txtDevname"/>
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Save" id="btnRegister"/>
</div>
</form>
In one of your #Configuration classes or #EnableAutoConfiguration class create a bean of CommonsRequestLoggingFilter, paste the code. This will log every incoming request
#Bean
public CommonsRequestLoggingFilter logFilter() {
CommonsRequestLoggingFilter filter
= new CommonsRequestLoggingFilter();
filter.setIncludeQueryString(true);
filter.setIncludePayload(true);
filter.setMaxPayloadLength(10000);
filter.setIncludeHeaders(false);
filter.setAfterMessagePrefix("REQUEST DATA : ");
return filter;
}
And in your application.properties file set logging level to DEBUG using logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=
DEBUG
All set! now call your endpoint from the WEB/Postman and check if you find the missing piece.
You need to use #RequestBody :
#RequestMapping(method=RequestMethod.POST, value="/tasks")
public ImModel createNote(#RequestBody ImModel note) {
return TaskRepository.save(note);
}
use the code written below.You need to add #RequestBody before ImModel note
#RequestMapping(method=RequestMethod.POST, value="/tasks")
public ImModel createNote(#RequestBody ImModel note) {
return TaskRepository.save(note);
}

Resources