本文整理汇总了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);
}
示例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失败,可能是由于密钥长度不匹配"));
}
}
示例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));
}
示例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;
}
示例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();
}
示例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);
}
示例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));
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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)));
}