I have a user dto class and i need to convert some of its properties before send it to frontend. UsedDto class Now, from my controller i get data like this In my case, before send data, i should convert boolean values (enabled, active) to string “Y” or “N”. How can i do this? Answer You can implement a custom
Tag: spring-mvc
How to implement configuration to use oracle/postgreSQL dataSource with spring+mybatis framework?
Background: spring + mybatis + oracle data source Requirement: support postgreSQL data source exchange with minimum code change Example: Current: controllerA -> ServiceA -> daoA -> A.xml (oracle) Now need: we can configure use oracele/postgreSQL database source If configure use postgreSQL: controllerA -> ServiceA -> daoA -> A.xml (postgreSQL) More: Same controllerA、ServiceA for same business logic Differenct DaoA、A.xml for oracle
Spring Controller GET/POST/PUT to another interface
I am using React as frontend and Java Spring Boot as backend. React sends JSON form data as GET/PUT/POST requests to my backend url (http://localhost:8080/test). Now, I wan’t to send this JSON forward to another interfaces GET endpoint (https://another/interface/add?id={id}). This interface then queries database based on the id and answers 200 OK message with a JSON reply which I need
POST: Exception Status expected: but was:
Technically it should be a simple task, but I can’t find the error. I want to write a normal “POST method”, but when I tested it, it came to a problem: enter code here Status expected:<201> but what:<200>. My question is, why do I get an OK and not a CREATED? CODE: PostMapping in Controller Unit Test Answer Because for
What do spring.mvc.view.prefix and spring.mvc.view.suffix have to be?
I created a Spring Boot demo app with Maven using Spring Initializr (that’s my almost the very first usage of Spring). It works, but for some reason doesn’t show any pages besides index.html. If I’m right, that’s because of configuration in application.properties, but I just don’t know, what have I add there. My project’s sources structure: I tried to add
Create RESTful web service for current logged user in Spring Boot
I have URL for user dashboard(/users/{userId}). I wanted to support /users/current for current logged user, and I searched for ways to implement that, and I did that by the following code. However, I think it’s too overwhelming and I wonder if there are better/simpler ways to do that. P. S. I think I made a much better solution with custom
Spring MVC POST request with dto that contains multipart files and other dtos
I have a DTO that contains other DTOs and a list of multipart files. I am trying to process that DTO but I can’t seem to be able to read the requst. When creating an example request from Swagger UI, I get the following exception: If I put @RequestBody instead of @ModelAttribute then I get Swagger dependencies: OpenAPI3.0 config: Answer
Store and retrieve an object in session through @Scope(“session”)
I am having a Spring shopping project and I am working on a cart with I can add new product to it and store it in the session. I create a Cart class to store it in the session I create a Controller class to get the cart from session and add product to it But when I call this
How to retrieve the URL of a RequestEntity obtained from RequestEntity.post(String, Object…)
I’m using Spring Boot 2.6.1 with Spring Web MVC, and in my controller, I want to get the received RequestEntity instead of only the request body, because I have to use information such as the URL. When I want to test my controller, I build a RequestEntity with the following code: Now, I don’t know how to retrieve the URL
Error creating entityManagerFactory.Unable building Hibernate SessionF.SchemaManagementException:Export identifier[new_user]encountered more than once
My controller class – My JpaRepository extended interface – My Pojo class – And , the errors which it is giving is – org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Export identifier [new_user] encountered