我想从spring web应用程序中获取插入mysql数据库中的'categoria'的id,这是我从spring开始的serviceImpl类。
package com.tomatubuk.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tomatubuk.Entidades.Categoria;
import com.tomatubuk.Repository.CategoryRepository;
@Service
public class CategoriaServiceImpl implements CategoriaService{
@Autowired
private CategoryRepository categoriarepository;
@Override
public Iterable<Categoria> ListAllCategoria() {
return categoriarepository.findAll();
}
@Override
public Categoria saveCategoria(Categoria categoria){
return categoriarepository.save(categoria);
}
@Override
public Iterable<Categoria> ListAllOrderASC() {
return categoriarepository.findAllOrderASC();
}
@Override
public Iterable<Categoria> ListAllOrderDESC() {
return categoriarepository.findAllOrderDESC();
}
}
这是我的catrgoria存储库,从我的serviceImpl类
调用package com.tomatubuk.Repository;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.tomatubuk.Entidades.Categoria;
@Repository
@Transactional
public interface CategoryRepository extends CrudRepository<Categoria,
Integer> {
@Query("Select c from Categoria c order by c.nombrecategoria asc")
public Iterable<Categoria> findAllOrderASC();
@Query("Select c from Categoria c order by c.nombrecategoria desc")
public Iterable<Categoria> findAllOrderDESC();
}
提前谢谢