spring.datasource.url=jdbc:mysql://localhost:3306/dbexamen
spring.datasource.username= root
spring.datasource.password= root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Repository
@Transactional
public interface ArticuloRepository extends CrudRepository<Articulo, Integer>
@RequestMapping(value="/articulo/new",method=RequestMethod.POST) //HOME
public String saveArticulo(@Valid Articulo a,BindingResult result,Model model){
try {
if(result.hasErrors()){
model.addAttribute("message",result.toString());
return "newArticulo";
}
precioventa=articuloService.calcularPrecioVenta(a);
articuloService.saveArticulo(a);
model.addAttribute("message",
"El precio de venta ="+precioventa);
return "newArticulo";
} catch (Exception e) {
// TODO: handle exception
model.addAttribute("message",
e.getMessage());
return "newArticulo";
}
}
////ejem de querys
List<Articulo> findByClavearticuloOrderByPrecioventaDesc(int clavearticulo);
@Query("select u from Articulo u where u.precioventa between ?1 and ?2 ")
List<Articulo> findByPrecioventaRange(double pv1, double pv2);
@Query("select count(u) from Articulo u where u.clavearticulo=?1")
int countArticuloClavearticulo(int clavearticulo);
No hay comentarios.:
Publicar un comentario