我正面临着这个特殊的问题。
首先,我将此作为我的控制器。
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import io.opus.storeconfigurables.model.Config;
import io.opus.storeconfigurables.service.StoreConfigurablesService;
@RestController
public class StoreConfigurablesController extends BaseEndpoint {
@Autowired
private StoreConfigurablesService service;
@RequestMapping(
value = "/{mode}/{id}",
method = RequestMethod.GET,
headers="Accept=*/*",
produces = MediaType.APPLICATION_JSON_VALUE)
@CrossOrigin(origins="*", maxAge=3600)
public ResponseEntity<List<Config>> listAllUsers(
@PathVariable("mode") String mode,
@PathVariable("id") String id) {
List<Config> configs = service.findAllConfigs(mode, id);
if(configs.isEmpty()){
return new ResponseEntity<List<Config>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND
}
return new ResponseEntity<List<Config>>(configs, HttpStatus.OK);
}
一切都像魅力一样。 http://localhost:8080/Store/XY29向我提供了我期待的JSON格式的回复。
最后,我添加了另一个控制器方法:
@RequestMapping(
value = "/{mode}/{id}/{rlNumber}",
method = RequestMethod.GET,
headers="Accept=*/*",
produces = MediaType.APPLICATION_JSON_VALUE)
@CrossOrigin(origins="*", maxAge=3600)
public ResponseEntity<List<Config>> listAllPermissions(
@PathVariable("mode") String mode,
@PathVariable("id") String id,
@PathVariable("rlNumber") String rlNumber) {
List<Config> configs = service.listAllPermissions(mode, id, rlNumber);
if(configs.isEmpty()){
return new ResponseEntity<List<Config>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND
}
return new ResponseEntity<List<Config>>(configs, HttpStatus.OK);
}
以及我之前来自浏览器的请求 - http://localhost:8080/Store/XY29 - 以及我对新控制器方法的新请求也因Whitelabel 406错误而失败。可能是什么原因?
我读到添加jackson jars到maven pom.xml可以解决这些问题,但也没有运气。