我正在使用 Hateoas 功能来调用 Controller 的 post 方法 url。但是当我尝试使用 ControllerLinkBuilder 类的 linkTo 方法时,我遇到了异常,如下所述:
Java类:
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import org.springframework.stereotype.Component;
@Component
public class CallController{
public String doThis()
{
ManagementResource resource = new ManagementResource();
resource.add(linkTo(DataController.class).withRel("postData"));
return "";
}
}
控制器类
@Controller
@RequestMapping("/data")
public class DataController {
@RequestMapping(method = RequestMethod.POST, value = "")
public ResponseEntity<ManagementResource> postData(@RequestBody Data1 data) {
RSResponse<Data1> response = new RSResponse<Data1>();
response.setStatus(RSResponse.Status.SUCCESS);
response.setData(data);
return new ResponseEntity<ManagementResource>(HttpStatus.CREATED);
}
}
如果有人对此有所了解,我在这里做错了什么,请告诉我。提前致谢。