无法识别@DeleteMapping

时间:2018-08-10 09:45:00

标签: spring-boot

我是春季靴子的新手,我的问题很简单,但是我找不到问题所在。

我有一个基本的@GetMapping和@DeleteMapping

@RestController
    public class MyController
    {
       private MyServiceImpl myService;

       @Autowired
       public MyController(MyServiceImpl myService)
       {
          this.myService = myService;
       }

       @GetMapping("/test")
       public List<Scan>  getTestData(@RequestParam(value = "test_id", required = true) String test_id) {
          return myService.findByTestId( test_id );
       }

      @DeleteMapping("/test")
       public int deleteData(@RequestParam(value = "test_id", required = true) String test_id){
          return myService.deleteTest( test_id );
       }

 @DeleteMapping("/test2")
   public String deleteArticle() {
      return "Test";
   }

    }

我正在与Postman进行测试,Get请求正在工作,但删除请求却没有。即使当我调试spring boot应用程序时。 GetMapping被调用,而删除不是“反应” /被调用

也许信息不够,但是我什至测试了 @DeleteMapping(“ / test2”)没有做任何事情,我的意思是,我没有任何反应,在Postman中它保持“正在加载。” 。”

有什么建议吗?

我完整的POM

http://maven.apache.org/xsd/maven-4.0.0.xsd“>     4.0.0

<parent>
    <groupId>com.ttt.pdt</groupId>
    <artifactId>pdt-base</artifactId>
    <version>2.0-SNAPSHOT</version>
</parent>

<artifactId>pdt-service</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>

</dependencies>
<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

父级(以pdt为基础)具有

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
</parent>

test_no is equivalent to test_id

MyServiceImpl

@Service
public class MyServiceImpl
{
   private ScnDao scnDao;

   @Autowired
   public ScanServiceImpl(ScnDao scnDao){
      this.scnDao = scnDao;
   }

   public int deleteTest( String test_id )
   {
      return scnDao.deleteTest( test_id );
   }

}

public interface ScanDao
{

   int deleteTest( String test_id )
}

@Repository
    public class ScnPostgres implements ScnDao
    {

       private JdbcTemplate jdbcTemplate;

       @Autowired
       public ScnPostgres( JdbcTemplate jdbcTemplate )
       {
          this.jdbcTemplate = jdbcTemplate;
       }

       public int deleteTest( String test_id )
        {
            String SQL = "DELETE FROM scn WHERE test_id = ?";
            return jdbcTemplate.update( SQL, new String[] { test_id } );
        }

    }

1 个答案:

答案 0 :(得分:0)

SPR-16874中所述,在SPR注释中:

  

它当前不支持DELETE。这将是一个微不足道的变化   使。建议一种解决方法:

@DeleteMapping(value = "/greeting")
public Greeting handle(@RequestBody MultiValueMap<String, String> params) {
    return new Greeting(counter.incrementAndGet(),
                        String.format(template, params));
}

您会看到issue已在spring boot跟踪器中打开。