Moved MediaTypeNotAcceptableException article from spring-mvc-java to spring-mvc-basics module, and added test

This commit is contained in:
Gerardo Roza
2019-07-15 13:07:01 -03:00
parent fc24c7b69b
commit 3150b6d4fd
4 changed files with 37 additions and 5 deletions

View File

@@ -16,7 +16,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Introduction to HtmlUnit](http://www.baeldung.com/htmlunit)
- [Upload and Display Excel Files with Spring MVC](http://www.baeldung.com/spring-mvc-excel-files)
- [web.xml vs Initializer with Spring](http://www.baeldung.com/spring-xml-vs-java-config)
- [The HttpMediaTypeNotAcceptableException in Spring MVC](http://www.baeldung.com/spring-httpmediatypenotacceptable)
- [Spring MVC @PathVariable with a dot (.) gets truncated](http://www.baeldung.com/spring-mvc-pathvariable-dot)
- [A Quick Example of Spring Websockets @SendToUser Annotation](http://www.baeldung.com/spring-websockets-sendtouser)
- [Working with Date Parameters in Spring](https://www.baeldung.com/spring-date-parameters)

View File

@@ -1,27 +0,0 @@
package com.baeldung.exception;
import org.springframework.http.MediaType;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.Map;
@RestController
public class HttpMediaTypeNotAcceptableExceptionExampleController {
@PostMapping(value = "/test", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> test() {
return Collections.singletonMap("key", "value");
}
@ResponseBody
@ExceptionHandler(HttpMediaTypeNotAcceptableException.class)
public String handleHttpMediaTypeNotAcceptableException() {
return "acceptable MIME type:" + MediaType.APPLICATION_JSON_VALUE;
}
}