在与sql server连接的spring boot api的postman中获取404状态代码

bogh5gae  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(384)

我的spring boot项目已连接到mssql服务器,但在postman中点击post响应获取404状态代码时:
Postman :

{
    "timestamp": 1625696983693,
    "status": 404,
    "error": "Not Found",
    "path": "/house"
  }

mycontroller.java

public class MyController {

    @Autowired
    private HouseService houseService;

    // get the values
    @GetMapping("/house")
    public List<House> getApiHouseValues(){
        return this.houseService.getHouseValues();
    }

    // add values
    @PostMapping("/house")
    public GateHouse addApiHouseValues(@RequestBody House house) {
        return this.houseService.addHouseValues(house);
    }
}

应用程序属性

server.port=9090
spring.datasource.url=jdbc:sqlserver://server-name;databaseName=log
spring.datasource.username=loguser
spring.datasource.password=test
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver

# hibernate configuration

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update 
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

也签入了sql server,但数据库是空的,不知道哪里出错了。

3htmauhk

3htmauhk1#

404表示找不到页面,请在控制器级别添加以下内容。

@RestController
@RequestMapping(value ="/")
public class MyController {

GetMapping("house")
public List<House> getApiHouseValues(){
    return this.houseService.getHouseValues();
 }
}

相关问题