没有将数据恢复到数据库中

时间:2017-06-28 16:05:05

标签: spring rest spring-mvc cors postman

我正在从Web服务模拟器发出PUT请求,但我没有将数据从它返回到我的数据库中。我尝试使用Postman进行模拟,所有功能都运行正常。我使用CORS来支持来自我的应用程序的AJAX调用。

附件是初始化类和控制器中CORS的代码片段。

有人可以建议任何解决方法吗?感谢

@Configuration
@EnableWebMvc
@ComponentScan
public class Application extends WebMvcConfigurerAdapter{
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**/*")
                .allowedOrigins("SOMEWEBSITE")
                .allowedMethods("GET","PUT","POST","DELETE","OPTIONS")
                .allowedHeaders("header1","header2","header3")
                .exposedHeaders("header1","header2")
                .allowCredentials(false)
                .maxAge(3600);
    }

@CrossOrigin(origins = "SOMEWEBSITE", maxAge = 3600)
@RestController
@RequestMapping(value = "/vehicles")
public class VehiclesController {

    @Autowired
    VehiclesService vehiclesService;

    @RequestMapping(method = RequestMethod.GET,
                    produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    //@CrossOrigin
    public List<Vehicle> findAllVehicles(){
        System.out.println("In controller");
        return vehiclesService.findAllVehicles();
    }

0 个答案:

没有答案