首页新闻找找看学习计划

spring-boot-webflux-mongodb 插入对象时报错 Prohibited character at position 0

0
悬赏园豆:5 [待解决问题]

model:

public class City {

/**
 * 城市编号
 */
@Id
private Long id;

/**
 * 省份编号
 */
private Long provinceId;

/**
 * 城市名称
 */
private String cityName;

/**
 * 描述
 */
private String description;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public Long getProvinceId() {
    return provinceId;
}

public void setProvinceId(Long provinceId) {
    this.provinceId = provinceId;
}

public String getCityName() {
    return cityName;
}

public void setCityName(String cityName) {
    this.cityName = cityName;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

}

repository:

@Repository
public interface CityRepository extends ReactiveMongoRepository<City,Long> {

}

handler:

@Component
public class CityHandler {

@Autowired
private CityRepository cityRepository;

public Mono<City> save(City city) {
    return cityRepository.save(city);
}

public Mono<City> findCityById(Long id) {
    return cityRepository.findById(id);
}

public Flux<City> findAll() {
    return cityRepository.findAll();
}
public Mono<City> modifyCity(City city) {
    return cityRepository.save(city);
}

public Mono<Long>  deleteCity(Long id) {
    cityRepository.deleteById(id);
    return Mono.create(cityMonoSink -> cityMonoSink.success(id));
}

}

controller:

@RestController
@RequestMapping("/city")
public class CityWebFluxController {

@Autowired
private CityHandler cityHandler;

@GetMapping(value = "/{id}")
public Mono<City> findCityById(@PathVariable("id") Long id) {
    return cityHandler.findCityById(id);
}

@GetMapping()
public Flux<City> findAllCity() {
    return cityHandler.findAll();
}

@PostMapping()
public Mono<City> saveCity(@RequestBody City city) {
    return cityHandler.save(city);
}

@PutMapping()
public Mono<City> modifyCity(@RequestBody City city) {
    return cityHandler.modifyCity(city);
}

@DeleteMapping(value = "/{id}")
public Mono<Long> deleteCity(@PathVariable("id") Long id) {
    return cityHandler.deleteCity(id);
}

}

mongodb是window的

spring:
data:
mongodb:
username: city
password: 123456
host: 127.0.0.1
port: 27017
database: city

littlecarzz的主页 littlecarzz | 初学一级 | 园豆:197
提问于:2019-08-31 11:21
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册