當前位置: 首頁>>代碼示例>>Java>>正文


Java ResponseEntity.ok方法代碼示例

本文整理匯總了Java中org.springframework.http.ResponseEntity.ok方法的典型用法代碼示例。如果您正苦於以下問題:Java ResponseEntity.ok方法的具體用法?Java ResponseEntity.ok怎麽用?Java ResponseEntity.ok使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.ResponseEntity的用法示例。


在下文中一共展示了ResponseEntity.ok方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: events

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@GetMapping("events")
HttpEntity<Resources<?>> events(PagedResourcesAssembler<AbstractEvent<?>> assembler,
		@SortDefault("publicationDate") Pageable pageable,
		@RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime since,
		@RequestParam(required = false) String type) {

	QAbstractEvent $ = QAbstractEvent.abstractEvent;

	BooleanBuilder builder = new BooleanBuilder();

	// Apply date
	Optional.ofNullable(since).ifPresent(it -> builder.and($.publicationDate.after(it)));

	// Apply type
	Optional.ofNullable(type) //
			.flatMap(events::findEventTypeByName) //
			.ifPresent(it -> builder.and($.instanceOf(it)));

	Page<AbstractEvent<?>> result = events.findAll(builder, pageable);

	PagedResources<Resource<AbstractEvent<?>>> resource = assembler.toResource(result, event -> toResource(event));
	resource
			.add(links.linkTo(methodOn(EventController.class).events(assembler, pageable, since, type)).withRel("events"));

	return ResponseEntity.ok(resource);
}
 
開發者ID:olivergierke,項目名稱:sos,代碼行數:27,代碼來源:EventController.java

示例2: createAuthenticationToken

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@ApiOperation(value = "授權", notes = "")
@ApiImplicitParams({
        @ApiImplicitParam(paramType = "query",name = "appName", value = "應用的名字", required = true,dataType = "String"),
        @ApiImplicitParam(paramType = "query",name = "vq",value = "vq",required = true,dataType = "String"),
        @ApiImplicitParam(paramType = "query",name = "device",value = "設備的名字",required = true,dataType = "String")})


@RequestMapping(value = "${jwt.route.authentication.path}", method = RequestMethod.POST)
public ResponseEntity<?> createAuthenticationToken(String appName,String vq, Device device) throws AuthenticationException {

    logger.info("應用:" + appName  + " 正在授權!");

    App app = appRepository.findFirstByAppname(appName);
    if (app == null) {
        return ResponseEntity.ok(new ErrorReporter(1, "未找到應用" + appName));
    }

    YibanOAuth yibanOAuth = new YibanOAuth(vq, app);
    yibanOAuth.dealYibanOauth();
    if (yibanOAuth.isHasError() == false) {
        upcYbUserFactory.createUser(yibanOAuth.getYibanBasicUserInfo());
        String ybid = String.valueOf(yibanOAuth.getYibanBasicUserInfo().visit_user.userid);
        String ybtocken = yibanOAuth.getYibanBasicUserInfo().visit_oauth.access_token;
        logger.info("ybtocken: " + ybtocken);
        final JwtUser userDetails = (JwtUser) userDetailsService.loadUserByUsername(ybid);
        final String token = jwtTokenUtil.generateToken(userDetails, ybtocken,appName, device);
        logger.info("發放token:" + token);
        return ResponseEntity.ok(new JwtAuthenticationResponse(token));
    } else {
        return ResponseEntity.ok(new ErrorReporter(2, "解析vq失敗,可能是由於密鑰長度不匹配"));
    }
}
 
開發者ID:upcyiban,項目名稱:Integrate,代碼行數:33,代碼來源:AuthenticationRestController.java

示例3: getVersion

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@RequestMapping(value = "/{id:.+}/{version:.+}", method = RequestMethod.GET)
public ResponseEntity<PluginVersion> getVersion(@PathVariable("id") String id,
                                                @PathVariable("version") String version) {
    PluginEntity plugin = pluginRepository.findByPluginNameEquals(id);

    if (null == plugin) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    PluginVersionEntity versionEntity = versionRepository.findByPluginEntityAndPluginVersionEquals(plugin, version);
    if (null == versionEntity) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    return ResponseEntity.ok(Transformer.fromPluginVersionEntity(versionEntity));
}
 
開發者ID:linkedin,項目名稱:custom-gradle-plugin-portal,代碼行數:17,代碼來源:PluginsResource.java

示例4: get

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.GET)
@ApiOperation(value = "Fetch locations", response = ResponseDTO.class)
public ResponseEntity<Map<String, Object>> get() {
  ResponseEntity<Map<String, Object>> result = ResponseEntity.notFound().build();
	try {
		Collection<LocationDTO> locationDTO = locationConverter.convertToDTO(locationService.get());
		if (CollectionUtils.isNotEmpty(locationDTO)) {
			ResponseDTO responseDTO = new ResponseDTO(ZvisitorResource.location.toString(), locationDTO);
			result = ResponseEntity.ok(responseDTO.getResponse());
		}
	} catch(Exception e) {
		logger.error("Exception while fetching location.", e);
		result = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
	}
	return result;
}
 
開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:17,代碼來源:LocationResource.java

示例5: getMacroPrediction

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@RequestMapping(value = "/macro", method = RequestMethod.POST)
public ResponseEntity getMacroPrediction(@PathVariable("userProfileId") Long userProfileId) {

    UserProfile userProfile = userProfileRespository.findOne(userProfileId);
    Target userTarget = targetRepository.findOne(userProfile.getTarget());
    Diets userDiet = dietsRepository.findDietByUserId(userProfileId);

    int energy = service.getEnergyIngestion(userProfile.getWeight(), userTarget.getValue());

    MacroData data;

    if (userDiet.getDiet() == 1) {
        data = service.getBalancedMacroDistribution(energy, userDiet.getCarbs(),
                userDiet.getLipids(), userDiet.getProteins());

        return ResponseEntity.ok(data);

    } else if (userDiet.getDiet() == 2) {
        data = service.getLowCarbMacroDistribution(energy, userDiet.getCarbs(),
                userDiet.getLipids(), userDiet.getProteins());

        return ResponseEntity.ok(data);
    } else if (userDiet.getDiet() == 3) {
        //TODO: get carbs, proteins, lipids provided by user
    }

    return ResponseEntity.unprocessableEntity().build();
}
 
開發者ID:novatrixtech,項目名稱:drnutrix-api,代碼行數:29,代碼來源:PredictionsProvider.java

示例6: setModelMap

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
/** 設置響應代碼 */
protected ResponseEntity<ModelMap> setModelMap(ModelMap modelMap, HttpCode code, Object data) {
	Map<String, Object> map = InstanceUtil.newLinkedHashMap();
	map.putAll(modelMap);
	modelMap.clear();
	for (Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext();) {
		String key = iterator.next();
		if (!key.startsWith("org.springframework.validation.BindingResult") && !key.equals("void")) {
			modelMap.put(key, map.get(key));
		}
	}
	if (data != null) {
		if (data instanceof Page) {
			Page<?> page = (Page<?>) data;
			modelMap.put("data", page.getRecords());
			modelMap.put("current", page.getCurrent());
			modelMap.put("size", page.getSize());
			modelMap.put("pages", page.getPages());
			modelMap.put("total", page.getTotal());
			modelMap.put("iTotalRecords", page.getTotal());
			modelMap.put("iTotalDisplayRecords", page.getTotal());
		} else if (data instanceof List<?>) {
			modelMap.put("data", data);
			modelMap.put("iTotalRecords", ((List<?>) data).size());
			modelMap.put("iTotalDisplayRecords", ((List<?>) data).size());
		} else {
			modelMap.put("data", data);
		}
	}
	modelMap.put("httpCode", code.value());
	modelMap.put("msg", code.msg());
	modelMap.put("timestamp", System.currentTimeMillis());
	return ResponseEntity.ok(modelMap);
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:35,代碼來源:BaseController.java

示例7: getInstanceCountByNamespace

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@RequestMapping(value = "/envs/{env}/instances/by-namespace/count", method = RequestMethod.GET)
public ResponseEntity<Number> getInstanceCountByNamespace(@PathVariable String env, @RequestParam String appId,
                                                          @RequestParam String clusterName,
                                                          @RequestParam String namespaceName) {

    int count = instanceService.getInstanceCountByNamepsace(appId, Env.valueOf(env), clusterName, namespaceName);
    return ResponseEntity.ok(new Number(count));
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:9,代碼來源:InstanceController.java

示例8: getReviews

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@ApiOperation("list reviews")
@Transactional
@RequestMapping(value = "getReviews", method = RequestMethod.GET)
public ResponseEntity<List<ReviewsRes>> getReviews(@ModelAttribute @Valid ReviewsReq vo) {
    List<ReviewsRes> resList = reviewsService.getReviews(vo);
    return ResponseEntity.ok(resList);
}
 
開發者ID:helloworldtang,項目名稱:spring-boot-jwt-jpa,代碼行數:8,代碼來源:ReviewsController.java

示例9: getRepo

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@RequestMapping(path = "/{id}", method = RequestMethod.GET)
public ResponseEntity<RepositoryDefinition> getRepo(@PathVariable("id") Long id) {
    RepositoryEntity repo = artifactRepositoryRepository.getOne(id);

    if(repo == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

    return ResponseEntity.ok(Transformer.fromRepositoryEntity(repo));
}
 
開發者ID:linkedin,項目名稱:custom-gradle-plugin-portal,代碼行數:11,代碼來源:RepositoryResource.java

示例10: getAllTodoLists

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
/**
 * Get all to do lists, both household and individual
 * @return the response entity with the to do list
 */
@RequestMapping(method = RequestMethod.GET, value = "/", produces = "application/json")
public ResponseEntity getAllTodoLists() {
    List<ITodoList> todoLists = this.todoListService.getAll();

    return ResponseEntity.ok(todoLists);
}
 
開發者ID:jackcmeyer,項目名稱:SmartSync,代碼行數:11,代碼來源:TodoListController.java

示例11: myProfile

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@RequestMapping("/api/profile")
public ResponseEntity<UserProfile> myProfile() {
    String username = (String) SecurityContextHolder.getContext()
            .getAuthentication().getPrincipal();
    String email = username + "@mailinator.com";

    UserProfile profile = new UserProfile(username, email);

    return ResponseEntity.ok(profile);
}
 
開發者ID:PacktPublishing,項目名稱:OAuth-2.0-Cookbook,代碼行數:11,代碼來源:UserController.java

示例12: getManifest

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<PluginManifest> getManifest() {
    Map<String, PluginIdContainer> collect = pluginRepository.findAll().stream()
            .map(Transformer::fromPluginEntity)
            .collect(Collectors.toMap(PluginIdContainer::getPluginId, item -> item));

    List<RepositoryDefinition> repos = artifactRepositoryRepository.findAll().stream()
            .map(Transformer::fromRepositoryEntity)
            .collect(Collectors.toList());

    return ResponseEntity.ok(new PluginManifest(collect, repos));
}
 
開發者ID:linkedin,項目名稱:custom-gradle-plugin-portal,代碼行數:13,代碼來源:ManifestResource.java

示例13: getHouseholdTodoListById

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
/**
 * Gets the household to do list with the id
 * @param id the id to find by
 * @return the response entity with the household to do list
 */
@RequestMapping(method = RequestMethod.GET, value = "/household/{id}", produces = "application/json")
public ResponseEntity getHouseholdTodoListById(@PathVariable("id") Long id) {
    HouseholdTodoList householdTodoList = this.todoListService.getHouseholdTodoListById(id);

    // check if the to do list exists
    if(householdTodoList == null) {
        String message = "Could not find to do list with id " + id;
        String url = "/todolist/household/" + id;

        throw new TodoListNotFoundException(message, url);
    }

    return ResponseEntity.ok(householdTodoList);
}
 
開發者ID:jackcmeyer,項目名稱:SmartSync,代碼行數:20,代碼來源:TodoListController.java

示例14: get

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@GetMapping("/{id}")
public HttpEntity<FooResource> get(@PathVariable UUID id) {
	log.info("Get {}", id);
	Foo foo = new Foo(id, "Foo");

	FooResource fooResource = assembler.toResource(foo);
	return ResponseEntity.ok(fooResource);

}
 
開發者ID:Devskiller,項目名稱:friendly-id,代碼行數:10,代碼來源:FooController.java

示例15: createClientUser

import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@ApiOperation(value = "create user", notes = "create a new user and assign it to the client")
@RequestMapping(value = "{id}/user", method = RequestMethod.POST)
public ResponseEntity<SmartiUserData> createClientUser(AuthContext authContext,
                                                       @PathVariable("id") ObjectId id,
                                                       @RequestBody SmartiUserData user) {
    final Client client = authenticationService.assertClient(authContext, id);

    if (StringUtils.isBlank(user.getLogin())) {
        return ResponseEntity.unprocessableEntity().build();
    }
    user.getClients().clear();

    return ResponseEntity.ok(SmartiUserData.fromModel(userService.createUserForClient(user.toModel(), client)));
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:15,代碼來源:ClientWebservice.java


注:本文中的org.springframework.http.ResponseEntity.ok方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。