我想测试Web服务,但由于此错误而无法启动服务器
我在哪里插入了@Autowired注释(在控制器中)
printf( "%d\n", **mat );
printf( "%d\n", ( *mat )[0] );
printf( "%d\n", *mat[0] );
printf( "%d\n", mat[0][0] );
这是我的界面ProductDao
@RestController
public class ProductController {
@Autowired
private ProductDao productDao;
//Récupérer la liste des produits
@RequestMapping(value="/Produits", method=RequestMethod.GET)
public List<Product>listeProduits() {
return productDao.findAll();
}
//Récupérer un produit par son Id
@GetMapping(value="/Produits/{id}")
public Product afficherUnProduit(@PathVariable int id) {
return productDao.findById(id);
}
//ajouter un produit
@PostMapping(value = "/Produits")
public void ajouterProduit(@RequestBody Product product) {
productDao.save(product);
}
}
答案 0 :(得分:0)
您需要在ProductDao接口上添加@Repository
批注并扩展扩展CrudRepository<ENT, Long>
像下面一样
@Repository
public interface ProductDao extends CrudRepository<ENT, Long>
// ENT是您的主键字段名称,Long是数据类型
您可以参考here,以更好地理解