Skip to content

Commit

Permalink
DB h2-console
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaiasMorochi committed Aug 17, 2019
1 parent 9ac077e commit db3c269
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<!-- <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
Expand Down Expand Up @@ -75,12 +70,15 @@ public String ver(@PathVariable(value = "id") Long id, Map<String, Object> model

@RequestMapping(value = "/listar", method = RequestMethod.GET)
public String listar(@RequestParam(name="page", defaultValue="0") int page, Model model) {

Pageable pageRequest = PageRequest.of(page, 4); //spring 5
Page<Cliente> clientes = clienteService.findAll(pageRequest);
PageRender<Cliente> pageRender = new PageRender<Cliente>("/listar", clientes);

model.addAttribute("titulo", "Listado de clientes");
model.addAttribute("clientes", clientes);
model.addAttribute("page", pageRender);

return "listar";
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/springboot/app/models/dao/IClienteDao.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.springboot.app.models.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.springboot.app.models.entity.Cliente;

public interface IClienteDao extends PagingAndSortingRepository<Cliente, Long> {

public interface IClienteDao extends JpaRepository<Cliente, Long> {
//PagingAndSortingRepository
}
17 changes: 10 additions & 7 deletions src/main/java/com/springboot/app/models/entity/Cliente.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.springboot.app.models.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.*;

import org.springframework.beans.FatalBeanException;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
Expand Down Expand Up @@ -39,6 +34,14 @@ public class Cliente implements Serializable {
@Temporal(TemporalType.DATE)
private Date createdAt;

/*
* Se crea el valor antes de insertar a la BD
*/
@PrePersist
public void prePersist(){
createdAt = new Date();
}

@OneToMany(mappedBy = "cliente", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Factura> facturas; //Un cliente tiene muchas Facturas

Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#################################
#Configuracion console de BD H2 #
#################################

#spring.datasource.url=jdbc:h2:men:clientesdb
#spring.datasource.username=isaias
#spring.datasource.password=sa
#spring.datasource.driver-class-name=org.h2.Driver
spring.h2.console.enabled=true
# default jdbc: testdb user: sa pass: <sinclave>
# localhost:8080/h2-console/

# FILE
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
3 changes: 2 additions & 1 deletion src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ NotEmpty.cliente.nombre= El nombre del clientes es requerido
NotEmpty.cliente.apellido= El apellido del cliente es requerido
NotEmpty.cliente.email= El email es requerido
Email.cliente.email= La direccion de correo no es valida
NotNull.cliente.createdAt= La fecha no puede ser nula
NotNull.cliente.createdAt= La fecha no puede ser nula
type.Mismatch.cliente.createdAt= Formato de la fecha invalido, debe ser: yyy-MM-dd
19 changes: 4 additions & 15 deletions src/main/resources/templates/layout/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,21 @@

<div class="row">
<div class="col-md-12">
<div th:fragment="contenido">

</div>
<div th:fragment="contenido"></div>
</div>
</div>


<footer th:fragment="footer" class="container">
<hr />
<div class="form-group row">

<img th:src="@{/img/spring.png}" alt="Spring logo" />

<p style="margin-top: 80px">
Powered by
<a href="https://projects.spring.io/spring-boot/">Spring Boot
</a> y
<p style="margin-top: 80px">Powered by
<a href="https://projects.spring.io/spring-boot/">Spring Boot</a> y
<a href="http://www.thymeleaf.org">Thymeleaf</a>.
</p>

</div>
<p>
Este proyecto fue desarrollado en IDE Eclipse + Spring Plugins (STS Spring Tool).
<br /> &copy; Company 2019, Inc. Todos los derechos reservados. Terminos de uso y privacidad.
<br />
</p>

<!-- Optional JavaScript -->
<!-- jQuery first, then Bootstrap JS -->
<script th:src="@{/js/jquery-3.2.1.min.js}"></script>
Expand Down

0 comments on commit db3c269

Please sign in to comment.