Merge pull request #10372 from Maiklins/JAVA-3531-move-spring-mvc-xml
Java 3531 move spring mvc xml
This commit is contained in:
commit
aec6ef01e4
2
pom.xml
2
pom.xml
|
@ -664,7 +664,6 @@
|
|||
<module>spring-mvc-java-2</module>
|
||||
|
||||
<module>spring-mvc-velocity</module>
|
||||
<module>spring-mvc-xml</module>
|
||||
|
||||
<module>spring-protobuf</module>
|
||||
<module>spring-quartz</module>
|
||||
|
@ -1129,7 +1128,6 @@
|
|||
<module>spring-mvc-java-2</module>
|
||||
|
||||
<module>spring-mvc-velocity</module>
|
||||
<module>spring-mvc-xml</module>
|
||||
|
||||
<module>spring-protobuf</module>
|
||||
<module>spring-quartz</module>
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<module>spring-mvc-forms-jsp</module>
|
||||
<module>spring-mvc-views</module>
|
||||
<module>spring-mvc-webflow</module>
|
||||
<module>spring-mvc-xml</module>
|
||||
<module>spring-rest-angular</module>
|
||||
<module>spring-rest-http</module>
|
||||
<module>spring-rest-query-language</module>
|
||||
|
|
|
@ -1,61 +1,61 @@
|
|||
package com.baeldung.spring.controller;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.context.support.ServletContextResource;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Controller
|
||||
public class ImageController {
|
||||
|
||||
@Autowired
|
||||
private ServletContext servletContext;
|
||||
|
||||
@RequestMapping(value = "/image-view", method = RequestMethod.GET)
|
||||
public String imageView() throws IOException {
|
||||
return "image-download";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/image-manual-response", method = RequestMethod.GET)
|
||||
public void getImageAsByteArray(HttpServletResponse response) throws IOException {
|
||||
final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg");
|
||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||
IOUtils.copy(in, response.getOutputStream());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/image-byte-array", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public byte[] getImageAsByteArray() throws IOException {
|
||||
final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg");
|
||||
return IOUtils.toByteArray(in);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/image-response-entity", method = RequestMethod.GET)
|
||||
public ResponseEntity<byte[]> getImageAsResponseEntity() throws IOException {
|
||||
ResponseEntity<byte[]> responseEntity;
|
||||
final HttpHeaders headers = new HttpHeaders();
|
||||
final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg");
|
||||
byte[] media = IOUtils.toByteArray(in);
|
||||
headers.setCacheControl(CacheControl.noCache().getHeaderValue());
|
||||
responseEntity = new ResponseEntity<>(media, headers, HttpStatus.OK);
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/image-resource", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Resource> getImageAsResource() {
|
||||
final HttpHeaders headers = new HttpHeaders();
|
||||
Resource resource = new ServletContextResource(servletContext, "/WEB-INF/images/image-example.jpg");
|
||||
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
package com.baeldung.spring.controller;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.context.support.ServletContextResource;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Controller
|
||||
public class ImageController {
|
||||
|
||||
@Autowired
|
||||
private ServletContext servletContext;
|
||||
|
||||
@RequestMapping(value = "/image-view", method = RequestMethod.GET)
|
||||
public String imageView() throws IOException {
|
||||
return "image-download";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/image-manual-response", method = RequestMethod.GET)
|
||||
public void getImageAsByteArray(HttpServletResponse response) throws IOException {
|
||||
final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg");
|
||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||
IOUtils.copy(in, response.getOutputStream());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/image-byte-array", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public byte[] getImageAsByteArray() throws IOException {
|
||||
final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg");
|
||||
return IOUtils.toByteArray(in);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/image-response-entity", method = RequestMethod.GET)
|
||||
public ResponseEntity<byte[]> getImageAsResponseEntity() throws IOException {
|
||||
ResponseEntity<byte[]> responseEntity;
|
||||
final HttpHeaders headers = new HttpHeaders();
|
||||
final InputStream in = servletContext.getResourceAsStream("/WEB-INF/images/image-example.jpg");
|
||||
byte[] media = IOUtils.toByteArray(in);
|
||||
headers.setCacheControl(CacheControl.noCache().getHeaderValue());
|
||||
responseEntity = new ResponseEntity<>(media, headers, HttpStatus.OK);
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/image-resource", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ResponseEntity<Resource> getImageAsResource() {
|
||||
final HttpHeaders headers = new HttpHeaders();
|
||||
Resource resource = new ServletContextResource(servletContext, "/WEB-INF/images/image-example.jpg");
|
||||
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
|
||||
}
|
||||
}
|
|
@ -1,22 +1,22 @@
|
|||
package com.baeldung.spring.validator;
|
||||
|
||||
import com.baeldung.spring.form.Person;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
public class PersonValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public boolean supports(final Class calzz) {
|
||||
return Person.class.isAssignableFrom(calzz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(final Object obj, final Errors errors) {
|
||||
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name");
|
||||
}
|
||||
package com.baeldung.spring.validator;
|
||||
|
||||
import com.baeldung.spring.form.Person;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
@Component
|
||||
public class PersonValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public boolean supports(final Class calzz) {
|
||||
return Person.class.isAssignableFrom(calzz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(final Object obj, final Errors errors) {
|
||||
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name");
|
||||
}
|
||||
}
|
|
@ -1,2 +1,2 @@
|
|||
required.name = Name is required!
|
||||
required.name = Name is required!
|
||||
NotEmpty.person.password = Password is required!
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
Loading…
Reference in New Issue