本文整理匯總了Java中org.springframework.web.bind.annotation.GetMapping類的典型用法代碼示例。如果您正苦於以下問題:Java GetMapping類的具體用法?Java GetMapping怎麽用?Java GetMapping使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GetMapping類屬於org.springframework.web.bind.annotation包,在下文中一共展示了GetMapping類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: login
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping(value = "/login")
public ModelAndView login(
@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout) {
logger.info("******login(error): {} ***************************************", error);
logger.info("******login(logout): {} ***************************************", logout);
ModelAndView model = new ModelAndView();
if (error != null) {
model.addObject("error", "Invalid username and password!");
}
if (logout != null) {
model.addObject("message", "You've been logged out successfully.");
}
model.setViewName("login");
return model;
}
示例2: serveFileOnline
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
/**
* 在線顯示文件
* @param id
* @return
*/
@GetMapping("/view/{id}")
@ResponseBody
public ResponseEntity<Object> serveFileOnline(@PathVariable String id) {
File file = fileService.getFileById(id);
if (file != null) {
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "fileName=\"" + file.getName() + "\"")
.header(HttpHeaders.CONTENT_TYPE, file.getContentType() )
.header(HttpHeaders.CONTENT_LENGTH, file.getSize()+"")
.header("Connection", "close")
.body( file.getContent());
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("File was not fount");
}
}
示例3: oneRawImage
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping(value = BASE_PATH + "/" + FILENAME + "/raw",
produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<?>> oneRawImage(
@PathVariable String filename) {
// tag::try-catch[]
return imageService.findOneImage(filename)
.map(resource -> {
try {
return ResponseEntity.ok()
.contentLength(resource.contentLength())
.body(new InputStreamResource(
resource.getInputStream()));
} catch (IOException e) {
return ResponseEntity.badRequest()
.body("Couldn't find " + filename +
" => " + e.getMessage());
}
});
// end::try-catch[]
}
示例4: handleFederationRequest
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
/**
* Handle federation request.
*
* @param response the response
* @param request the request
* @throws Exception the exception
*/
@GetMapping(path = WSFederationConstants.ENDPOINT_FEDERATION_REQUEST)
protected void handleFederationRequest(final HttpServletResponse response, final HttpServletRequest request) throws Exception {
final WSFederationRequest fedRequest = WSFederationRequest.of(request);
switch (fedRequest.getWa().toLowerCase()) {
case WSFederationConstants.WSIGNOUT10:
case WSFederationConstants.WSIGNOUT_CLEANUP10:
handleLogoutRequest(fedRequest, request, response);
break;
case WSFederationConstants.WSIGNIN10:
handleInitialAuthenticationRequest(fedRequest, response, request);
break;
default:
throw new UnauthorizedAuthenticationException("The authentication request is not recognized",
Collections.emptyMap());
}
}
示例5: verArticulo
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping("/articulo/{id}")
public String verArticulo (Model model, @PathVariable long id,HttpServletRequest request){
Articulo articulo = articulo_repository.findOne(id);
model.addAttribute("articulo", articulo);
model.addAttribute("comentarios",comentario_repository.findByArticulo(articulo));
model.addAttribute("admin",request.isUserInRole("ADMIN"));
return "ver_articulo";
}
示例6: getSwitches
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
/**
* Get all available links.
*
* @return list of links.
*/
@ApiOperation(value = "Get all available switches", response = SwitchDto.class)
@ApiResponses(value = {
@ApiResponse(code = 200, response = FlowPayload.class, message = "Operation is successful"),
@ApiResponse(code = 400, response = MessageError.class, message = "Invalid input data"),
@ApiResponse(code = 401, response = MessageError.class, message = "Unauthorized"),
@ApiResponse(code = 403, response = MessageError.class, message = "Forbidden"),
@ApiResponse(code = 404, response = MessageError.class, message = "Not found"),
@ApiResponse(code = 500, response = MessageError.class, message = "General error"),
@ApiResponse(code = 503, response = MessageError.class, message = "Service unavailable")})
@GetMapping(path = "/switches")
@ResponseStatus(HttpStatus.OK)
public List<SwitchDto> getSwitches() {
return switchService.getSwitches();
}
示例7: tweetSingle
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping(value = "/tweet/{year}/{month}/{day}/{title}")
public String tweetSingle(@PathVariable("year") Integer year,@PathVariable("month") Integer month,@PathVariable("day") Integer day,@PathVariable("title") String title, Model model) {
model.addAttribute("tweet","selected");
Article article = articleService.getArticleByTitle(title);
model.addAttribute("article",article);
List<String> tagsList = articleService.getArticleTagsByArticleId(article.getId());
model.addAttribute("tagsList",tagsList.toString());
return "front/theme/effe/tweetSingle";
}
示例8: getClassFile
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping(value = "get_class_file")
public void getClassFile(@RequestParam List<String> tableNames,
@RequestParam String url,
@RequestParam String userName,
@RequestParam String password,
@RequestParam(required = false) String pkgName,
HttpServletResponse response) throws SQLException, IOException {
Connection conn = getConn(url, userName, password);
Map<String, List<String>> nameWithJavaMap = getStringListMap(tableNames, conn, pkgName);
conn.close();
ServletOutputStream outputStream = response.getOutputStream();
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
for (Map.Entry<String, List<String>> stringListEntry : nameWithJavaMap.entrySet()) {
zipOutputStream.putNextEntry(
new ZipEntry(
getJavaClassName(stringListEntry.getKey()) + ".java"
)
);
for (String line : stringListEntry.getValue()) {
zipOutputStream.write(line.getBytes());
zipOutputStream.write('\n');
}
}
response.setContentType("application/zip;charset=utf-8");
response.setHeader("Content-disposition", "attachment;filename= " + LocalDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE) + ".zip");
zipOutputStream.close();
}
示例9: editPage
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
/**
* 編輯用戶頁
*
* @param id
* @param model
* @return
*/
@GetMapping("/editPage")
public String editPage(Model model, Long id) {
UserVo userVo = userService.selectVoById(id);
List<Role> rolesList = userVo.getRolesList();
List<Long> ids = new ArrayList<Long>();
for (Role role : rolesList) {
ids.add(role.getId());
}
model.addAttribute("roleIds", ids);
model.addAttribute("user", userVo);
return "admin/user/userEdit";
}
示例10: defaultAfterLogin
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping("/default")
public String defaultAfterLogin(HttpServletRequest request) {
if (request.isUserInRole("ROLE_ADMIN")) {
return "redirect:/events/";
}
return "redirect:/";
}
示例11: confirm
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
/**
* Receive non-password protected message.
*/
@GetMapping("/confirm/{id:[a-f0-9]{64}}")
public String confirm(
@PathVariable("id") final String id,
@ModelAttribute("linkSecret") final String linkSecret,
final Model model,
final HttpSession session) {
prepareMessage(id, linkSecret, null, model, session);
return FORM_MSG_DISPLAY;
}
示例12: showCodeCouple
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping("/")
ResponseEntity<String> showCodeCouple(){
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
HttpEntity<?> entity = new HttpEntity<>(headers);
return restTemplate.exchange(
"http://producer-service/",
HttpMethod.GET,
entity,
String.class);
}
示例13: users
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping("/users")
public ResponseEntity<String> users() {
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<String>() {
};
return restTemplate.exchange(SERVICE, HttpMethod.GET, authenticationService.addAuthenticationHeader(), reference);
}
示例14: validateToken
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
@GetMapping("/{token:.+}")
public ResponseEntity validateToken(@CookieValue("time") String time,
@RequestHeader("Authorization") String[] authorization, @PathVariable String token,
@RequestParam String url) {
String temp = tokens.get(token);
String auth = authorization[0];
if (auth.equals("dummy")) {
auth = authorization[1];
}
if (temp.equals(time) && auth.equals(token + time + url)) {
return ResponseEntity.ok().build();
} else {
return ResponseEntity.badRequest().build();
}
}
示例15: file
import org.springframework.web.bind.annotation.GetMapping; //導入依賴的package包/類
/**
* Download attached file.
*/
@GetMapping("/file/{id:[a-f0-9]{64}}/{key:[a-f0-9]{64}}")
public ResponseEntity<StreamingResponseBody> file(@PathVariable("id") final String id,
@PathVariable("key") final String keyHex,
final HttpSession session) {
final KeyIv keyIv =
new KeyIv(BaseEncoding.base16().lowerCase().decode(keyHex), resolveFileIv(id, session));
final DecryptedFile decryptedFile = messageService.resolveStoredFile(id, keyIv);
final HttpHeaders headers = new HttpHeaders();
// Set application/octet-stream instead of the original mime type to force download
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
if (decryptedFile.getName() != null) {
headers.setContentDispositionFormData("attachment", decryptedFile.getName(),
StandardCharsets.UTF_8);
}
headers.setContentLength(decryptedFile.getOriginalFileSize());
final StreamingResponseBody body = out -> {
try (final InputStream in = messageService.getStoredFileInputStream(id, keyIv)) {
ByteStreams.copy(in, out);
out.flush();
}
messageService.burnFile(id);
};
return new ResponseEntity<>(body, headers, HttpStatus.OK);
}