This commit is contained in:
iizmg
2019-05-13 11:28:53 +08:00
parent f6a13d8dfd
commit 8760ff30fc
3 changed files with 32 additions and 8 deletions
@@ -0,0 +1,22 @@
package org.itkk.udf.demo.server.core;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/demo/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH");
}
};
}
}
@@ -2,11 +2,13 @@ package org.itkk.udf.demo.server.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DemoEntity {
private String name;
private Date date;
@@ -1,26 +1,26 @@
package org.itkk.udf.demo.server.web;
import lombok.extern.slf4j.Slf4j;
import org.itkk.udf.demo.server.domain.DemoEntity;
import org.itkk.udf.demo.server.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.web.bind.annotation.*;
import java.util.Date;
@RestController("demoController")
@RequestMapping("demo")
@Slf4j
public class DemoController {
@Autowired
private DemoService demoService;
@RequestMapping(method = RequestMethod.GET, path = "t1/{name}")
public DemoEntity t1(@PathVariable String name) {
demoService.t1();
return new DemoEntity(name,new Date());
@RequestMapping(method = RequestMethod.POST, path = "t1/{name}")
public DemoEntity t1(@RequestBody DemoEntity demoEntity, @PathVariable String name) {
log.info("demoEntity:", demoEntity);
//demoService.t1();
return new DemoEntity(name, new Date());
}
}