Java 在Spring中使用ResponseEntity在@RestController和@Controller之间传递数据
我必须使用Java 在Spring中使用ResponseEntity在@RestController和@Controller之间传递数据,java,spring,controller,Java,Spring,Controller,我必须使用ResponseEntity类将对象从RestController传递到控制器。第一个请求将使用下面的链接转到AuthRestController.class 然后经过一些处理,它将被重定向到另一个控制器,该控制器是以下链接上的ResponseController 在这里,我无法将状态对象传递给ResponseControl AuthRestController.class @RestController @RequestMapping(value = "/auth/apis")
ResponseEntity
类将对象从RestController传递到控制器。第一个请求将使用下面的链接转到AuthRestController.class
然后经过一些处理,它将被重定向到另一个控制器,该控制器是以下链接上的ResponseController
在这里,我无法将状态对象传递给ResponseControl
AuthRestController.class
@RestController
@RequestMapping(value = "/auth/apis")
public class AuthRestController {
@Autowired Environment environment;
@Autowired UserService userService;
@Autowired StatusService statusService;
@RequestMapping(value = "/status", method = RequestMethod.GET)
public ResponseEntity<Status> status(@RequestParam String sts, @RequestParam String hsh) {
HttpHeaders httpHeaders = new HttpHeaders();
Status status = new Status(0, "undefined", "any status that does not exists in the system", "something's getting wrong");
try {
if (!hsh.trim().equals("") && !sts.trim().equals("")) {
String userId = Base64Utils.decrypt(URLDecoder.decode(hsh.trim(), "UTF-8").replace(" ", "+")).split("\\-")[0].trim();
User user = userService.getUser(Integer.parseInt(userId));
if (user != null && user.getUserKey() != null && user.getUserKey().equals(hsh.trim())) {
String decrypted = Base64Utils.decrypt(URLDecoder.decode(sts.trim(), "UTF-8").replace(" ", "+"));
status = statusService.getStatus(Integer.parseInt(decrypted));
user.setStatus(status);
user.setUserKey(null);
userService.updateUser(user);
}
}
httpHeaders.setLocation(new URI(environment.getRequiredProperty("application.domain")
+ "app/response/acknowledgement"));
} catch (Exception e) {
Log.e(e);
}
return new ResponseEntity<Status>(status, httpHeaders, HttpStatus.SEE_OTHER);
}
}
@Controller
@RequestMapping("/app/response")
public class ResponseController {
@RequestMapping(value = "/acknowledgement", method = RequestMethod.POST)
public String acknowledgement(ModelMap model) {
// How to get Status object here sent from AuthRestController?
// To be passed in model as attribute
model.addAttribute("msg", status.getMessage());
return "acknowledgement";
}
}
那么,有没有办法在acknowledge()方法中获取状态实例?或者我的方法有什么问题
谢谢这听起来像是在做Spring Security开箱即用的工作。这听起来像是在做Spring Security开箱即用的工作。