本文整理匯總了Java中org.springframework.util.StringUtils.pathEquals方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.pathEquals方法的具體用法?Java StringUtils.pathEquals怎麽用?Java StringUtils.pathEquals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.pathEquals方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setWebAppRootSystemProperty
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
* Set a system property to the web application root directory.
* The key of the system property can be defined with the "webAppRootKey"
* context-param in {@code web.xml}. Default is "webapp.root".
* <p>Can be used for tools that support substition with {@code System.getProperty}
* values, like log4j's "${key}" syntax within log file locations.
* @param servletContext the servlet context of the web application
* @throws IllegalStateException if the system property is already set,
* or if the WAR file is not expanded
* @see #WEB_APP_ROOT_KEY_PARAM
* @see #DEFAULT_WEB_APP_ROOT_KEY
* @see WebAppRootListener
* @see Log4jWebConfigurer
*/
public static void setWebAppRootSystemProperty(ServletContext servletContext) throws IllegalStateException {
Assert.notNull(servletContext, "ServletContext must not be null");
String root = servletContext.getRealPath("/");
if (root == null) {
throw new IllegalStateException(
"Cannot set web app root system property when WAR file is not expanded");
}
String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM);
String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY);
String oldValue = System.getProperty(key);
if (oldValue != null && !StringUtils.pathEquals(oldValue, root)) {
throw new IllegalStateException(
"Web app root system property already set to different value: '" +
key + "' = [" + oldValue + "] instead of [" + root + "] - " +
"Choose unique values for the 'webAppRootKey' context-param in your web.xml files!");
}
System.setProperty(key, root);
servletContext.log("Set web app root system property: '" + key + "' = [" + root + "]");
}
示例2: register
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
@RequestMapping(value = "/register",method = RequestMethod.POST)
@ApiOperation(value = "Register user")
public ResponseEntity<?> register(@RequestBody AuthRequest authRequest) throws AuthenticationException{
logger.debug("Register with \r\n"+authRequest.toString());
if (authRequest==null || StringUtils.isEmpty(authRequest.getUsername())){
throw new UsernameNotFoundException("Username is empty.");
}
String captcha = captchaService.getCachedCaptcha(authRequest.getUsername());
if (StringUtils.isEmpty(captcha)){
throw new BadCaptchaException("Captcha is empty");
}
if (!StringUtils.pathEquals(captcha,authRequest.getCaptcha())){
throw new BadCaptchaException("Bad captcha");
}
if (StringUtils.isEmpty(authRequest.getPassword())){
throw new BadCredentialsException("Bad credentials");
}
if (userService.isUserExist(authRequest.getUsername())){
throw new UserExistException("User has existed");
}
boolean result = userService.createUser(authRequest.getUsername(),authRequest.getPassword());
if (result){
return ResponseEntity.ok(AuthResponse.success());
} else {
logger.warn("Create user failed.");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(AuthResponse.failure("Create user failed"));
}
}