Browse Source

Pruebas carga datos

master
Juanjo 1 year ago
parent
commit
20a71ccd75
12 changed files with 99 additions and 24 deletions
  1. +14
    -0
      pom.xml
  2. +1
    -5
      src/main/java/es/fp/edu/conecta2/BDMariaDB.java
  3. +17
    -1
      src/main/java/es/fp/edu/conecta2/Conecta2Application.java
  4. +2
    -2
      src/main/java/es/fp/edu/conecta2/controladores/ApiControlador.java
  5. +0
    -13
      src/main/java/es/fp/edu/conecta2/controladores/Controlador01.java
  6. +26
    -0
      src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java
  7. +1
    -0
      src/main/java/es/fp/edu/conecta2/modelo/user/User.java
  8. +2
    -0
      src/main/java/es/fp/edu/conecta2/repo/admin/IAdminRepo.java
  9. +2
    -0
      src/main/java/es/fp/edu/conecta2/repo/user/IUserRepo.java
  10. +7
    -0
      src/main/java/es/fp/edu/conecta2/servicios/UserService.java
  11. +26
    -3
      src/main/resources/application.properties
  12. +1
    -0
      src/main/resources/data.sql

+ 14
- 0
pom.xml View File

@ -50,6 +50,20 @@
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-mongodb -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>4.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>


src/main/java/es/fp/edu/conecta2/BDConfig.java → src/main/java/es/fp/edu/conecta2/BDMariaDB.java View File

@ -22,7 +22,7 @@ import java.util.Map;
entityManagerFactoryRef = "userEntityManagerFactory",
transactionManagerRef = "userTransactionManger",
basePackages = {"es.fp.edu.conecta2.repo.user"})
public class BDConfig {
public class BDMariaDB {
@Autowired
private Environment env;
@ -63,8 +63,4 @@ public class BDConfig {
return transactionManager;
}
}

+ 17
- 1
src/main/java/es/fp/edu/conecta2/Conecta2Application.java View File

@ -1,13 +1,29 @@
package es.fp.edu.conecta2;
import es.fp.edu.conecta2.modelo.user.User;
import es.fp.edu.conecta2.repo.user.IUserRepo;
import es.fp.edu.conecta2.servicios.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Conecta2Application {
public class Conecta2Application implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(Conecta2Application.class, args);
}
@Autowired
private UserService repositorioUser;
@Override
public void run(String... args) throws Exception {
User user1 = new User();
user1.setIdUsuario(1);
user1.setNombres("Juanjo");
//repositorioUser.registrar(user1);
}
}

src/main/java/es/fp/edu/conecta2/controladores/TestController.java → src/main/java/es/fp/edu/conecta2/controladores/ApiControlador.java View File

@ -9,8 +9,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/databases")
public class TestController {
@RequestMapping("/api")
public class ApiControlador {
@Autowired
private AdminService adminService;

+ 0
- 13
src/main/java/es/fp/edu/conecta2/controladores/Controlador01.java View File

@ -1,13 +0,0 @@
package es.fp.edu.conecta2.controladores;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Controlador01 {
@GetMapping ("/")
public String prueba() {
return "Esto es una prueba";
}
}

+ 26
- 0
src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java View File

@ -0,0 +1,26 @@
package es.fp.edu.conecta2.controladores;
import es.fp.edu.conecta2.repo.user.IUserRepo;
import es.fp.edu.conecta2.servicios.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class WebControlador {
@GetMapping ("/")
public String prueba() {
return "Esto es una prueba";
}
@Autowired
private UserService servicioUser;
@GetMapping ("/user")
public String listarUser(Model modelo){
modelo.addAttribute("user",servicioUser.listarUser());
return "usuarios";
}
}

+ 1
- 0
src/main/java/es/fp/edu/conecta2/modelo/user/User.java View File

@ -8,6 +8,7 @@ import jakarta.persistence.Table;
@Entity
@Table(name="tbl_user")
public class User {
public Integer getIdUsuario() {
return idUsuario;
}


+ 2
- 0
src/main/java/es/fp/edu/conecta2/repo/admin/IAdminRepo.java View File

@ -2,7 +2,9 @@ package es.fp.edu.conecta2.repo.admin;
import es.fp.edu.conecta2.modelo.admin.Admin;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface IAdminRepo extends JpaRepository<Admin, Integer> {
}

+ 2
- 0
src/main/java/es/fp/edu/conecta2/repo/user/IUserRepo.java View File

@ -2,6 +2,8 @@ package es.fp.edu.conecta2.repo.user;
import es.fp.edu.conecta2.modelo.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface IUserRepo extends JpaRepository<User,Integer> {
}

+ 7
- 0
src/main/java/es/fp/edu/conecta2/servicios/UserService.java View File

@ -5,6 +5,8 @@ import es.fp.edu.conecta2.repo.user.IUserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserService {
@Autowired
@ -13,5 +15,10 @@ public class UserService {
public void registrar(User t){
repo.save(t);
}
public List<User> listarUser(){
return repo.findAll();
}
}

+ 26
- 3
src/main/resources/application.properties View File

@ -22,11 +22,34 @@ persistente.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialec
persistente.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
#persistente.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
#persistente.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
persistente.sql.init.platform=mariadb
persistente.datasource.data=data.sql
persistente.jpa.defer-datasource-initialization=true
persistente.sql.init.mode=always
temporal.datasource.url=jdbc:h2:mem:temporal
temporal.datasource.url=jdbc:h2:mem:test
temporal.h2.console.enabled=true
temporal.h2.console.settings.trace=false
temporal.h2.console.settings.web-allow-others=false
temporal.datasource.username=sa
temporal.datasource.password=
temporal.datasource.driver-class-name=org.h2.Driver
temporal.jpa.show-sql=true
temporal.jpa.hibernate.ddl-auto=create-drop
temporal.jpa.database-platform=org.hibernate.dialect.H2Dialect
temporal.jpa.hibernate.ddl-auto=update
temporal.jpa.database-platform=org.hibernate.dialect.H2Dialect
redis.redis.port=9323
redis.redis.database=0
redis.redis.host=localhost
redis.redis.password=mypass
redis.redis.timeout=60000
mongo.data.mongodb.authentication-database=admin
mongo.data.mongodb.username=root
mongo.data.mongodb.password=root
mongo.data.mongodb.database=test_db
mongo.data.mongodb.port=27017
mongo.data.mongodb.host=localhost

+ 1
- 0
src/main/resources/data.sql View File

@ -0,0 +1 @@
insert into bolsa.tbl_user values (1,"Juan"), (2,"Perico"), (3,"Andrés");

Loading…
Cancel
Save