本文整理匯總了Java中org.springframework.web.bind.ServletRequestDataBinder.bind方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletRequestDataBinder.bind方法的具體用法?Java ServletRequestDataBinder.bind怎麽用?Java ServletRequestDataBinder.bind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.bind.ServletRequestDataBinder
的用法示例。
在下文中一共展示了ServletRequestDataBinder.bind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: bind
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
private void bind(ServletRequest request, ServletRequestDataBinder dataBinder) {
MutablePropertyValues mpvs = new ServletRequestParameterPropertyValues(request);
MultipartRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartRequest.class);
if (multipartRequest != null) {
bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
}
String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
if (uriVars != null) {
for (Map.Entry<String, String> entry : uriVars.entrySet()) {
if (mpvs.contains(entry.getKey())) {
logger.warn("Skipping URI variable '" + entry.getKey()
+ "' since the request contains a bind value with the same name.");
} else {
mpvs.addPropertyValue(entry.getKey(), entry.getValue());
}
}
}
this.extendDataBinder.doExtendBind(mpvs, dataBinder);
dataBinder.bind(mpvs);
}
開發者ID:superhj1987,項目名稱:spring-mvc-model-attribute-alias,代碼行數:25,代碼來源:SuishenServletModelAttributeMethodProcessor.java
示例2: getErrorsForNewForm
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Create a BindException instance for a new form.
* Called by {@link #showNewForm}.
* <p>Can be used directly when intending to show a new form but with
* special errors registered on it (for example, on invalid submit).
* Usually, the resulting BindException will be passed to
* {@link #showForm(HttpServletRequest, HttpServletResponse, BindException)},
* after registering the errors on it.
* @param request current HTTP request
* @return the BindException instance
* @throws Exception in case of an invalid new form object
* @see #showNewForm
* @see #showForm(HttpServletRequest, HttpServletResponse, BindException)
* @see #handleInvalidSubmit
*/
protected final BindException getErrorsForNewForm(HttpServletRequest request) throws Exception {
// Create form-backing object for new form.
Object command = formBackingObject(request);
if (command == null) {
throw new ServletException("Form object returned by formBackingObject() must not be null");
}
if (!checkCommand(command)) {
throw new ServletException("Form object returned by formBackingObject() must match commandClass");
}
// Bind without validation, to allow for prepopulating a form, and for
// convenient error evaluation in views (on both first attempt and resubmit).
ServletRequestDataBinder binder = createBinder(request, command);
BindException errors = new BindException(binder.getBindingResult());
if (isBindOnNewForm()) {
logger.debug("Binding to new form");
binder.bind(request);
onBindOnNewForm(request, command, errors);
}
// Return BindException object that resulted from binding.
return errors;
}
示例3: bindAndValidate
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Bind the parameters of the given request to the given command object.
* @param request current HTTP request
* @param command the command to bind onto
* @return the ServletRequestDataBinder instance for additional custom validation
* @throws Exception in case of invalid state or arguments
*/
protected final ServletRequestDataBinder bindAndValidate(HttpServletRequest request, Object command) throws Exception {
ServletRequestDataBinder binder = createBinder(request, command);
BindException errors = new BindException(binder.getBindingResult());
if (!suppressBinding(request)) {
binder.bind(request);
onBind(request, command, errors);
if (this.validators != null && isValidateOnBinding() && !suppressValidation(request, command, errors)) {
for (int i = 0; i < this.validators.length; i++) {
ValidationUtils.invokeValidator(this.validators[i], command, errors);
}
}
onBindAndValidate(request, command, errors);
}
return binder;
}
示例4: exportHandler
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
public ModelAndView exportHandler(HttpServletRequest request, HttpServletResponse resp) throws Exception {
getLog().info("ExportHandler()");
ExportCommand command = new ExportCommand();
command.setContext(onecmdb);
ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
binder.bind(request);
try {
resp.setContentType(command.getContentType());
//resp.setContentLength(-1);
OutputStream out = resp.getOutputStream();
command.transfer(out);
out.flush();
} catch (Throwable e) {
e.printStackTrace();
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST, "Error:" + e.getMessage());
}
return(null);
}
示例5: onBindAndValidate
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
@Override
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception {
super.onBindAndValidate(request, command, errors);
SiteCommand site = (SiteCommand) command;
// data is here bound into site, including the current action
SiteAction action = site.getAction();
if (action == null) {
// we are coming here without having an action
errors.addError(new ObjectError("SiteController", null, null,
"No Action set!"));
return;
}
// initiate the action, via the parameters in the request
ServletRequestDataBinder binder = new ServletRequestDataBinder(action);
binder.bind(request);
}
示例6: testBind
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
@Test
public void testBind() {
command = new RouteAssignmentCommand();
request = new MockHttpServletRequest();
request.addParameter("legs[0].voyageNumber", "CM01");
request.addParameter("legs[0].fromUnLocode", "AAAAA");
request.addParameter("legs[0].toUnLocode", "BBBBB");
request.addParameter("legs[1].voyageNumber", "CM02");
request.addParameter("legs[1].fromUnLocode", "CCCCC");
request.addParameter("legs[1].toUnLocode", "DDDDD");
request.addParameter("trackingId", "XYZ");
ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
binder.bind(request);
assertThat(command.getLegs()).hasSize(2).extracting("voyageNumber", "fromUnLocode", "toUnLocode")
.containsAll(Arrays.asList(Tuple.tuple("CM01", "AAAAA", "BBBBB"), Tuple.tuple("CM02", "CCCCC", "DDDDD")));
assertThat(command.getTrackingId()).isEqualTo("XYZ");
}
示例7: authHandler
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Command(s)
*/
/*
* Auth Command.
*/
public ModelAndView authHandler(HttpServletRequest request, HttpServletResponse resp) throws Exception {
getLog().info("AuthHandler()");
AuthCommand command = new AuthCommand(this.onecmdb);
ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
binder.bind(request);
try {
String token = command.getToken();
resp.setContentLength(token.length());
resp.setContentType("text/plain");
resp.getOutputStream().write(token.getBytes());
} catch (Exception e) {
resp.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE, "Authentication Failed!");
}
return(null);
}
示例8: validateAssertion
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Validate assertion.
*
* @param request the request
* @param serviceTicketId the service ticket id
* @param assertion the assertion
* @return the boolean
*/
private boolean validateAssertion(final HttpServletRequest request, final String serviceTicketId, final Assertion assertion) {
final ValidationSpecification validationSpecification = this.getCommandClass();
final ServletRequestDataBinder binder = new ServletRequestDataBinder(validationSpecification, "validationSpecification");
initBinder(request, binder);
binder.bind(request);
if (!validationSpecification.isSatisfiedBy(assertion)) {
logger.debug("Service ticket [{}] does not satisfy validation specification.", serviceTicketId);
return false;
}
return true;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:21,代碼來源:AbstractServiceValidateController.java
示例9: validateAssertion
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Validate assertion.
*
* @param request the request
* @param serviceTicketId the service ticket id
* @param assertion the assertion
* @return true/false
*/
private boolean validateAssertion(final HttpServletRequest request, final String serviceTicketId, final Assertion assertion) {
this.validationSpecification.reset();
final ServletRequestDataBinder binder = new ServletRequestDataBinder(this.validationSpecification, "validationSpecification");
initBinder(request, binder);
binder.bind(request);
if (!this.validationSpecification.isSatisfiedBy(assertion, request)) {
LOGGER.warn("Service ticket [{}] does not satisfy validation specification.", serviceTicketId);
return false;
}
return true;
}
示例10: bind
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* Bind request parameters onto the given command bean
* @param request request from which parameters will be bound
* @param command command object, that must be a JavaBean
* @throws Exception in case of invalid state or arguments
*/
protected void bind(HttpServletRequest request, Object command) throws Exception {
logger.debug("Binding request parameters onto MultiActionController command");
ServletRequestDataBinder binder = createBinder(request, command);
binder.bind(request);
if (this.validators != null) {
for (Validator validator : this.validators) {
if (validator.supports(command.getClass())) {
ValidationUtils.invokeValidator(validator, command, binder.getBindingResult());
}
}
}
binder.closeNoCatch();
}
示例11: bindRequestParameters
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* This implementation downcasts {@link WebDataBinder} to
* {@link ServletRequestDataBinder} before binding.
* @see ServletRequestDataBinderFactory
*/
@Override
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
servletBinder.bind(servletRequest);
}
示例12: bindRequestParameters
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request,MethodParameter parameter) {
Namespace annot = parameter.getParameterAnnotation(Namespace.class);
String attrName= (annot != null) ? annot.value() : null;
if(StringUtils.hasText(attrName)){
binder.setFieldDefaultPrefix(attrName+":");
}
ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
servletBinder.bind(servletRequest);
}
示例13: bindRequestParameters
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* This implementation downcasts {@link WebDataBinder} to
* {@link ServletRequestDataBinder} before binding.
*
* @see ServletRequestDataBinderFactory
*/
@Override
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request) {
ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
servletBinder.bind(servletRequest);
}
示例14: resolveArgument
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
String name = UifConstants.DEFAULT_MODEL_NAME;
Object attribute = null;
if (mavContainer.containsAttribute(name)) {
attribute = mavContainer.getModel().get(name);
}
WebDataBinder binder = binderFactory.createBinder(webRequest, attribute, name);
if (binder.getTarget() != null) {
ServletRequest servletRequest = webRequest.getNativeRequest(ServletRequest.class);
ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
servletBinder.bind(servletRequest);
if (binder.getBindingResult().hasErrors()) {
if (isBindExceptionRequired(parameter)) {
throw new BindException(binder.getBindingResult());
}
}
}
Map<String, Object> bindingResultModel = binder.getBindingResult().getModel();
mavContainer.removeAttributes(bindingResultModel);
mavContainer.addAllAttributes(bindingResultModel);
return binder.getTarget();
}
示例15: bind
import org.springframework.web.bind.ServletRequestDataBinder; //導入方法依賴的package包/類
public void bind(ServletRequest request, ServletRequestDataBinder binder) {
Map<String, ?> values = parseValues(request, binder);
MutablePropertyValues mpvs = new MutablePropertyValues(values);
MultipartRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartRequest.class);
if (multipartRequest != null) {
bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
}
// two lines copied from ExtendedServletRequestDataBinder
String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
mpvs.addPropertyValues((Map<String, String>) request.getAttribute(attr));
binder.bind(mpvs);
}