我有以下简单的项目来测试 Spring Boot 验证。我使用的是 Spring boot 版本 2.5.6
pom.xml 中的验证依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
DTO对象
import javax.validation.constraints.NotNull;
public class DepartmentDTO {
@NotNull(message = "Department name can not be empty")
private String name;
// getter and setter
}
Run Code Online (Sandbox Code Playgroud)
休息控制器
@RestController
public class DepartmentResource {
@PostMapping("/departments")
public ResponseEntity<DepartmentDTO> createDepartment(@Valid @RequestBody DepartmentDTO department) {
return new ResponseEntity<>(department, HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
当我触发具有空名称的请求时,我收到错误响应,但消息丢失:
{
"timestamp": "2021-12-03T09:13:52.729+00:00",
"status": 400,
"error": "Bad Request",
"path": "/departments"
}
Run Code Online (Sandbox Code Playgroud) 我使用以下 REST 服务(来自本教程)使用 jersey 多部分实现将文件从不同数量的客户端上传到我的 GlassFish 服务器:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
@Path("/fileupload")
public class UploadFileService {
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) {
String uploadedFileLocation = "c://uploadedFiles/" + fileDetail.getFileName();
// save it
saveToFile(uploadedInputStream, uploadedFileLocation);
String output = "File uploaded via Jersey based RESTFul Webservice to: " + uploadedFileLocation;
return Response.status(200).entity(output).build();
}
// save …Run Code Online (Sandbox Code Playgroud) I have two graphs on one page, which zoom and pan I want to be able to control with the same RangeSelector. In other words when I move the RangeSelector both graphs should react simultaneously.
The values in my first graph are small numbers between 2 and 20, and the numbers in my second graph have big values > 3000. This is the reason I don't want to put both lines in the same graph. Both graphs have the same …
我想知道如何隐藏网页的源代码.这是具有隐藏源的网页示例(右键单击 - >查看页面源).任何想法或建议?
更新我完全同意,完全隐藏HTML源是不可能的,否则浏览器无法解析它.使用FireBub等工具会向您显示来源.上面例子中有趣的是"显示源代码",显示的页面与输出不匹配.现在我明白这只是这里使用的另一种技术 - XSLT.谢谢你的回复!
java ×3
javascript ×2
rest ×2
dygraphs ×1
glassfish ×1
html ×1
jakarta-ee ×1
jersey ×1
obfuscation ×1
spring-boot ×1