我有一个用@ControllerAdvice它注释的类和这个方法:
@ExceptionHandler(ResourceNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public ExceptionInfo resourceNotFoundHandler(ResourceNotFoundException ex) {
List<ErrorContent> errors = new ArrayList<>();
errors.add(new ErrorContent(ExceptionsCodes.NOT_FOUND_CODE, null,
"test"));
return fillExceptionInfo(HttpStatus.NOT_FOUND, errors, ex);
}
Run Code Online (Sandbox Code Playgroud)
这是fillExceptionInfo:
public ExceptionInfo fillExceptionInfo(HttpStatus status, List<ErrorContent> errors,
Exception ex) {
String msg = ex.getMessage();
return new ExceptionInfo(status.toString(), errors, (msg != null && !msg.equals(""))
? ex.getMessage()
: ExceptionUtils.getFullStackTrace(ex));
}
Run Code Online (Sandbox Code Playgroud)
当Web客户端发送一些无法找到的json数据请求时,此方法可以正常工作.但是当服务器收到映像请求时,而不是我的异常a HttpMediaTypeNotAcceptableException抛出.我知道它是因为错误的内容类型而发生的,但我该如何解决这个问题呢?
更新
我的目标是ResourceNotFoundException为json数据和文件提供两种情况.
我得到的例外(因此它被抛出AbstractMessageConverterMethodProcessor):
ERROR o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - doResolveHandlerMethodException - Failed to invoke @ExceptionHandler method: public com.lia.utils.GlobalExceptionHandler$ExceptionInfo com.lia.utils.GlobalExceptionHandler.resourceNotFoundHandler(com.lia.app.controllers.exceptions.ResourceNotFoundException)
org.springframework.web.HttpMediaTypeNotAcceptableException: Could …Run Code Online (Sandbox Code Playgroud) 我对的行为感到困惑@RequestParam(value="someValue")。在文档中说
使用控制器接口时(例如,用于AOP代理),请确保将所有映射注释(例如@RequestMapping和@SessionAttributes)一致地放在控制器接口上,而不是在实现类上。
如果我把@RequestParam我的控制器接口它value完全忽略(并因此映射值null,如果参数名是从接收到的参数名称不同),但defaultValue并required工作正常。
如果我将其放置@RequestParam在控制器实现中,则一切正常。
我读了这个答案,但我不明白为什么有些参数有效而另一些无效,以及文档错误。
代码示例:
接口:
@RequestMapping(method = RequestMethod.GET)
List<MyObject> get(
//works if parameter in request has name "userName", which is not correct
@RequestParam(value = "username", required = false) String userName,
@RequestParam(value = "searchValue", required = false) String searchValue,
@RequestParam(value = "someId", required = false) Integer someId);
Run Code Online (Sandbox Code Playgroud)
实施:
@Override
public List<MyObject> get(
String userName,
String searchValue,
Integer someId) {
return myService.get(userName, …Run Code Online (Sandbox Code Playgroud) 如何在PostgreSQL数据库中使用liquibase创建double precision []类型的列(双精度数组)?
<changeSet id="add t_name table">
<createTable tableName="t_name">
...
<column name="doubleArray" type="???"/>
...
</createTable>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
Google并没有帮助,如果有人知道解决方案,我将不胜感激。