我正在使用Spring Boot项目,作为我目前的工具,几乎每个API我都有请求和响应类.
例如:
@RequestMapping(value = "/notice", method = RequestMethod.POST)
public AddNoticeResponse addNotice(@Valid @RequestBody AddNoticeRequest){
Notice notice = ... // creating new notice from AddNoticeRequest
noticeRepository.save(notice);
AddNoticeResponse response = ... // creating new response instance from Notice
return response;
}
Run Code Online (Sandbox Code Playgroud)
请求和响应类看起来像:
@Data
@AllArgsConstructor
public class AddNoticeRequest{
private String subject;
private String message;
private Long timeToLive;
}
Run Code Online (Sandbox Code Playgroud)
// Ommiting some annotations for brevity
public class AddNoticeResponse{
private String subject;
private String message;
private Long timeToLive;
private Date createTime; …
Run Code Online (Sandbox Code Playgroud) 我有两个实体类 Request,User:
//Ommiting some annotations for brevity
public class User{
private Long id;
private String name;
private Integer age;
}
public class Request{
private Long id;
private String message;
private Date createTime;
@ManyToOne
@JoinColumn(name="user_id")
private User user;
}
Run Code Online (Sandbox Code Playgroud)
我可以按创建时间对请求列表进行排序:
Sort = new Sort(Direction.ASC,"createTime");
Run Code Online (Sandbox Code Playgroud)
有没有办法按用户名对请求列表进行排序?喜欢:
Sort = new Sort(Direction.ASC,"User.name");
Run Code Online (Sandbox Code Playgroud) 我目前正在一个网站上工作,后端有Spring,前端有Angularjs,我们讨论了后端响应以处理前端的消息对话框,我有一个问题要问:
假设我有一个API:
GET : /getstatistics
Request params : fromTime,toTime ( in timestamp format)
Run Code Online (Sandbox Code Playgroud)
如果客户端使用无效的params(如字符串)发出请求,应该从服务器返回哪个响应代码?HTTP 400错误的请求和响应正文,消息"fromTime和toTime应该是时间戳格式"或HTTP 200具有相同的消息?
我看到一些谷歌的API,例如Oauth,他们为无效access_token的请求返回代码200但是,在我们的项目中,我认为它应该是HTTP 400,因为Javascript有成功和错误回调,它是否更好它只是弹出一个红色内部消息而不是HTTP 200代码的颜色对话框然后仍然需要检查消息的内容?
任何建议和意见表示赞赏.
谢谢!
我正在阅读https://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html
有参数:
mappedfile - 我们是否应该为每个输入行生成一个print语句的静态内容,以便于调试?true或false,默认为true.
但我无法理解这个参数的详细用法是什么,我试图谷歌但没有帮助.有人可以告诉我它是什么.