spring-mvc

HttpMessageNotReadableException: Required request body is missing (Occasional) - SpringMVC Default Controller Request Mapping HTTP Method?

纵饮孤独 提交于 2020-12-15 17:50:35
问题 I have the following code which represents an Ajax POST request: @RequestMapping("/participant/insertEvent") public boolean insertEvent(Principal principal, @RequestBody String json, HttpServletRequest request) throws Exception { //... //return true or false } JS: $.ajax({ type : "post", dataType : "json", url : '/app/participant/insertEvent', data : JSON.stringify({'p1': p1, 'p2' : p2}) }); The app is deployed in Production and everything has been working with many users the whole week. This

Bad Request from saving structured JSON object

笑着哭i 提交于 2020-12-15 05:25:25
问题 I have created a simple web REST application that has to save a "change ticket" to database. But after I try to create a POST request with JSON as body I get an error: 2020-11-28 14:06:10.449 DEBUG 14864 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed 400 BAD_REQUEST 2020-11-28 14:06:10.453 DEBUG 14864 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error", parameters={} 2020-11-28 14:06:10.455 DEBUG 14864 --- [nio-8080-exec-2] s.w.s.m

How to do validation in Spring MVC when there's a DTO?

我怕爱的太早我们不能终老 提交于 2020-12-15 05:15:30
问题 I have a person class and a personList DTO. The DTO is used to bind a list of persons object to the view. The user can edit one or more persons and click save to save the edits of all of them at once. Now I want to validate the new input. The problem is that the controller code "bindingResults.hasErrors()" is not returning the user input errors. I think it's because there's the personList DTO in the middle. Seems it is checking just errors in the personList class, but not in the person class

How to do validation in Spring MVC when there's a DTO?

空扰寡人 提交于 2020-12-15 05:12:04
问题 I have a person class and a personList DTO. The DTO is used to bind a list of persons object to the view. The user can edit one or more persons and click save to save the edits of all of them at once. Now I want to validate the new input. The problem is that the controller code "bindingResults.hasErrors()" is not returning the user input errors. I think it's because there's the personList DTO in the middle. Seems it is checking just errors in the personList class, but not in the person class

How to do validation in Spring MVC when there's a DTO?

陌路散爱 提交于 2020-12-15 05:10:15
问题 I have a person class and a personList DTO. The DTO is used to bind a list of persons object to the view. The user can edit one or more persons and click save to save the edits of all of them at once. Now I want to validate the new input. The problem is that the controller code "bindingResults.hasErrors()" is not returning the user input errors. I think it's because there's the personList DTO in the middle. Seems it is checking just errors in the personList class, but not in the person class

How to do validation in Spring MVC when there's a DTO?

怎甘沉沦 提交于 2020-12-15 05:10:01
问题 I have a person class and a personList DTO. The DTO is used to bind a list of persons object to the view. The user can edit one or more persons and click save to save the edits of all of them at once. Now I want to validate the new input. The problem is that the controller code "bindingResults.hasErrors()" is not returning the user input errors. I think it's because there's the personList DTO in the middle. Seems it is checking just errors in the personList class, but not in the person class

Read a resource from URL and return directly those bytes as response of REST request, with no memory storing with Java 7 and spring MVC 3.2

情到浓时终转凉″ 提交于 2020-12-15 04:40:11
问题 I have a REST endpoint that has to be accessed to retrieve a resource (image, document, ...). @RequestMapping(value = "/attachement", method = RequestMethod.GET) @ResponseBody public Object getTrademarkAttachement(HttpServletResponse response, HttpServletRequest request) { //TODO : Retrieve bytes from microservice url //TODO : Send bytes to frontend page } For retrieving this document, I want to do it via streaming . I don't want to store in memory the info . I want to , as I get the info,

Read a resource from URL and return directly those bytes as response of REST request, with no memory storing with Java 7 and spring MVC 3.2

半腔热情 提交于 2020-12-15 04:38:06
问题 I have a REST endpoint that has to be accessed to retrieve a resource (image, document, ...). @RequestMapping(value = "/attachement", method = RequestMethod.GET) @ResponseBody public Object getTrademarkAttachement(HttpServletResponse response, HttpServletRequest request) { //TODO : Retrieve bytes from microservice url //TODO : Send bytes to frontend page } For retrieving this document, I want to do it via streaming . I don't want to store in memory the info . I want to , as I get the info,

Thymeleaf + Spring MVC - Thymeleaf template parsing error on using checkbox input

主宰稳场 提交于 2020-12-13 11:31:41
问题 I'm following this tutorial which uses Spring MVC, Spring Boot and Thymeleaf as the view. I'm getting a Template Parsing Error when I use a checkbox input on the HTML form, and strangely, when I remove the checkbox input, everything works well. Here is the HTML - <!DOCTYPE html> <html lang="en" xmlns:th="https://www.thymeleaf.org/"> <head> <meta charset="UTF-8"> <title>Home Page</title> <style> h1,h2 { color: rebeccapurple; } </style> </head> <body> <h1>This is home page</h1> <h2>Enter data

Thymeleaf + Spring MVC - Thymeleaf template parsing error on using checkbox input

情到浓时终转凉″ 提交于 2020-12-13 11:31:32
问题 I'm following this tutorial which uses Spring MVC, Spring Boot and Thymeleaf as the view. I'm getting a Template Parsing Error when I use a checkbox input on the HTML form, and strangely, when I remove the checkbox input, everything works well. Here is the HTML - <!DOCTYPE html> <html lang="en" xmlns:th="https://www.thymeleaf.org/"> <head> <meta charset="UTF-8"> <title>Home Page</title> <style> h1,h2 { color: rebeccapurple; } </style> </head> <body> <h1>This is home page</h1> <h2>Enter data