我正在使用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);
}
}
如果有人对此有所了解,我在这里做错了,请告诉我。提前谢谢。