· 8 years ago · Nov 29, 2017, 10:30 AM
1/*ADMIN*/
2
3@Entity
4@Table(name="personas")
5@NamedQuery(
6 name="Admin.buscarPorNombre",
7 query="select r from Admin r where r.nombres=?1"
8 )
9public class Admin {
10 @Id
11 @GeneratedValue(strategy=GenerationType.AUTO)
12 int id;
13 @NotEmpty(message="no puede estar vacio")
14 String nombres;
15 @NotBlank(message="no puede estar en blanco")
16 String apellidos;
17
18 @NotBlank(message="no puede estar vacio")
19 @Email(message="debe tener formato de arroba")
20 @Size(min=3,max=20)
21 String correo;
22 int genero;
23
24 @ManyToOne(fetch=FetchType.LAZY)
25 Distrito distrito;
26
27 @ManyToOne(fetch=FetchType.LAZY)
28 Universidad universidad;
29}
30
31@Repository
32public interface AdminRepositorio extends JpaRepository<Admin, Integer> {
33
34 public List<Admin> buscarPorNombre(String nombre);
35}
36
37@Service
38public interface AdminService {
39
40 public Admin buscarPorId(int id);
41 public List<Admin> listado();
42 public boolean agregar(Admin personas);
43 public boolean elimnar(int id);
44 public boolean actualizar(Admin personas);
45 public List<Admin> buscarPorNombre(String nombre);
46}
47
48
49@Service
50public class AdminServiceImpl implements AdminService {
51
52 @Autowired
53 private AdminRepositorio repositorioInterface;
54
55 @Override
56 public Admin buscarPorId(int id) {
57 // TODO Auto-generated method stub
58 return repositorioInterface.findOne(id);
59 }
60
61 @Override
62 public List<Admin> listado() {
63 // TODO Auto-generated method stub
64 List<Admin> personas=repositorioInterface.findAll();
65 return personas;
66 }
67
68 @Override
69 public boolean agregar(Admin personas) {
70 // TODO Auto-generated method stub
71 Admin objpersonas=repositorioInterface.save(personas);
72 if (objpersonas==null) {
73 return false;
74 } else {
75 return true;
76 }
77 }
78
79 @Override
80 public boolean elimnar(int id) {
81 // TODO Auto-generated method stub
82 boolean flag=false;
83 try {
84 repositorioInterface.delete(id);
85 flag=true;
86 } catch (Exception e) {
87 // TODO: handle exception
88 System.out.println(e.getMessage());
89 }
90 return flag;
91 }
92
93 @Override
94 public boolean actualizar(Admin personas) {
95 // TODO Auto-generated method stub
96 boolean flag=false;
97 try {
98 repositorioInterface.save(personas);
99 flag=true;
100 } catch (Exception e) {
101 // TODO: handle exception
102 System.out.println(e.getMessage());
103 }
104 return flag;
105 }
106
107 @Override
108 public List<Admin> buscarPorNombre(String nombre) {
109 // TODO Auto-generated method stub
110 return repositorioInterface.buscarPorNombre(nombre);
111 }
112
113}
114
115
116/*Distrito*/
117
118@Entity
119@Table(name="distritos")
120public class Distrito {
121 @Id
122 @GeneratedValue(strategy=GenerationType.AUTO)
123 int id;
124 String nombre;
125 @OneToMany(mappedBy="distrito", fetch=FetchType.LAZY)
126 List<Admin> personas;
127}
128
129
130@Repository
131public interface DistritoRepositorio extends JpaRepository<Distrito , Integer> {
132
133}
134
135
136@Service
137public interface DistritoService {
138
139 public List<Distrito> listado();
140}
141
142
143@Service
144public class DistritoServiceImpl implements DistritoService {
145 @Autowired
146 private DistritoRepositorio repositorioInterface;
147
148 @Override
149 public List<Distrito> listado() {
150 // TODO Auto-generated method stub
151 List<Distrito> distritos=repositorioInterface.findAll();
152 return distritos;
153 }
154}
155
156
157/*Universid*/*/
158
159@Entity
160@Table(name="universidades")
161public class Universidad {
162 @Id
163 @GeneratedValue(strategy=GenerationType.AUTO)
164 int id;
165 String nombre;
166
167 @OneToMany(mappedBy="universidad", fetch=FetchType.LAZY)
168 List<Admin> personas;
169}
170
171
172@Repository
173public interface UniversidadRepositorio extends JpaRepository<Universidad, Integer>{
174
175}
176
177@Service
178public interface UniversidadService {
179 public List<Universidad> listado();
180}
181
182@Service
183public class UniversidadServiceImpl implements UniversidadService{
184 @Autowired
185 private UniversidadRepositorio repositorioInterface;
186
187 @Override
188 public List<Universidad> listado() {
189 // TODO Auto-generated method stub
190 List<Universidad> universidades=repositorioInterface.findAll();
191 return universidades;
192 }
193}
194
195/*controles*/
196
197@Controller
198public class AdminController {
199 @Autowired
200 AdminService adminService;
201 @Autowired
202 DistritoService distService;
203 @Autowired
204 UniversidadService univService;
205
206
207
208 @RequestMapping(value={"/","/admin/persona/listado"})
209 public String listado(Model model){
210 List<Admin> personas=adminService.listado();
211 model.addAttribute("personaListado", personas);
212 return "admin/persona_listado";
213 }
214
215 @RequestMapping(value="/admin/persona/nuevo")
216 public String nuevo(Model model){
217 model.addAttribute("distritoNuevo", distService.listado());
218 model.addAttribute("universidadNuevo", univService.listado());
219
220 Admin objPersona=new Admin();
221 model.addAttribute("personaMuevo", objPersona);
222 return "admin/persona_nuevo";
223 }
224
225 @RequestMapping(value="/admin/persona/guardar", method=RequestMethod.POST)
226 public String guardar(@ModelAttribute Admin objPersonas,RedirectAttributes objRed, Model model,BindingResult binRes){
227
228 if (binRes.hasErrors()) {
229 return "admin/persona_nuevo";
230 } else {
231 boolean flag=adminService.agregar(objPersonas);
232 if (flag) {
233 objRed.addFlashAttribute("mensaje", "se agrego correctamente");
234 return "redirect:/admin/persona/listado";
235 } else {
236 model.addAttribute("mensaje", "No se pudo guardar");
237 return "admin/persona_nuevo";
238 }
239 }
240
241 }
242
243 @RequestMapping(value="/admin/persona/eliminar/{id}")
244 public String eliminar(@PathVariable int id, RedirectAttributes objRed, Model model){
245 boolean flag=adminService.elimnar(id);
246 if (flag) {
247 objRed.addFlashAttribute("mensaje", "se elimino correctamente");
248 return "redirect:/admin/persona/listado";
249 } else {
250 objRed.addFlashAttribute("mensaje", "No se elimino correctamente");
251 return "redirect:/admin/persona/listado";
252 }
253 }
254
255 @RequestMapping(value="/admin/persona/editar/{id}")
256 public String editar(@PathVariable int id, RedirectAttributes objRed, Model model){
257 Admin objPersona=adminService.buscarPorId(id);
258 model.addAttribute("distritoEditado", distService.listado());
259 model.addAttribute("universidadEditado", univService.listado());
260
261 if (objPersona==null) {
262 objRed.addFlashAttribute("mensaje", "no hay personas");
263 return "redirect:/admin/persona/listado";
264 } else {
265 model.addAttribute("personaEditado", objPersona);
266 return "admin/persona_editado";
267 }
268 }
269
270 @RequestMapping(value="/admin/persona/actualizar", method=RequestMethod.POST)
271 public String actualizar(@ModelAttribute Admin objPersonas,RedirectAttributes objRed, Model model){
272 boolean flag=adminService.actualizar(objPersonas);
273 if (flag) {
274 objRed.addFlashAttribute("mensaje", "se actualiz correctamente");
275 return "redirect:/admin/persona/listado";
276 } else {
277 objRed.addFlashAttribute("mensaje", "No se actualiz correctamente");
278 return "redirect:/admin/persona/listado";
279 }
280 }
281
282 @RequestMapping(value="/admin/persona/buscarPorNombre")
283 public String busquedaPorNombre(@ModelAttribute Admin objPersona,Model model){
284 model.addAttribute("listadoPersona", adminService.buscarPorNombre(objPersona.getNombres()));
285 return "admin/persona_listado";
286 }
287
288 @RequestMapping(value={"/admin","/admin/"})
289 public String login(){
290
291 return "";
292 }
293
294 @RequestMapping(value="/admin/dashboard")
295 public String dashboard(){
296
297 return "";
298 }
299}
300
301/*html*/
302listado...
303<!-- <div> Buscar Por Nombre:
304 <form th:object="${personaListado}" action="/admin/persona/buscarPorNombre" method="get">
305 <input th:field="*{nombres}" />
306 <button type="submit" class="btn btn-default">Buscar</button>
307 </form>
308 </div> -->
309 <table class="table">
310 <thead>
311 <tr>
312 <th>Nombres</th>
313 <th>Apellidos</th>
314 <th>Correo</th>
315 <th>Distrito</th>
316 <th>Universidad</th>
317 <th>Genero</th>
318 <th>Opciones</th>
319
320 </tr>
321 </thead>
322 <tbody>
323 <tr th:each="persona: ${personaListado}">
324 <td th:text="${persona.nombres}"></td>
325 <td th:text="${persona.apellidos}"></td>
326 <td th:text="${persona.correo}"></td>
327 <td th:text="${persona.distrito.nombre}"></td>
328 <td th:text="${persona.universidad.nombre}"></td>
329 <td th:text="((${persona.genero}=='2')? 'femenino' : 'masculino')"></td>
330 <td>
331 <a th:href="@{'/admin/persona/editar/'+${persona.id}}">editar</a>
332 <a th:href="@{'/admin/persona/eliminar/'+${persona.id}}">eliminar</a>
333 </td>
334 </tr>
335 </tbody>
336 </table>
337
338nuevo...
339 <h1 class="page-header">Persona nuevo</h1>
340 <div th:text="${mensaje}" class="alert alert-success" role="alert">...</div>
341
342 <form th:object="${personaMuevo}" method="post" action="/admin/persona/guardar">
343
344 <div class="form-group">
345 <label for="campo01">Nombres</label>
346 <input th:field="*{nombres}" type="text" class="form-control" id="campo01" placeholder="Texto" />
347 <div th:if="${#fields.hasErrors('nombres')}" th:errors="*{nombres}"></div>
348 </div>
349
350 <div class="form-group">
351 <label for="campo01">Apellidos</label>
352 <input th:field="*{apellidos}" type="text" class="form-control" id="campo01" placeholder="Texto" />
353 <div th:if="${#fields.hasErrors('apellidos')}" th:errors="*{apellidos}"></div>
354 </div>
355
356 <div class="form-group">
357 <label for="exampleInputEmail1">Correo</label>
358 <input th:field="*{correo}" type="email" class="form-control" id="exampleInputEmail1" placeholder="Email" />
359 <div th:if="${#fields.hasErrors('correo')}" th:errors="*{correo}"></div>
360 </div>
361
362 <div class="form-group">
363 <label for="">Distrito</label>
364 <select th:field="*{distrito}" class="form-control">
365 <option th:each="distrito: ${distritoNuevo}" th:value="${distrito.id}" th:text="${distrito.nombre}"></option>
366
367 </select>
368 </div>
369 <div class="form-group">
370 <label for="">Universidad</label>
371 <select th:field="*{universidad}" class="form-control">
372 <option th:each="universidad: ${universidadNuevo}" th:value="${universidad.id}" th:text="${universidad.nombre}"></option>
373
374 </select>
375 </div>
376
377
378 <div class="form-group">
379 <label for="">Genero</label>
380
381 <div class="radio">
382 <label>
383 <input th:field="*{genero}" type="radio" name="optionsRadios" id="optionsRadios2" value="2" />
384 femenino
385 </label>
386 </div>
387 <div class="radio">
388 <label>
389 <input th:field="*{genero}" type="radio" name="optionsRadios" id="optionsRadios2" value="1" />
390 masculino
391 </label>
392 </div>
393
394 </div>
395
396 <button type="submit" class="btn btn-default">Agregar</button>
397 </form>
398edit..
399
400<h1 class="page-header">Persona nuevo</h1>
401 <div th:text="${mensaje}" class="alert alert-success" role="alert">...</div>
402
403 <form th:object="${personaEditado}" method="post" action="/admin/persona/actualizar">
404 <input th:field="*{id}" />
405 <div class="form-group">
406 <label for="campo01">Nombres</label>
407 <input th:field="*{nombres}" type="text" class="form-control" id="campo01" placeholder="Texto" />
408
409 </div>
410
411 <div class="form-group">
412 <label for="campo01">Apellidos</label>
413 <input th:field="*{apellidos}" type="text" class="form-control" id="campo01" placeholder="Texto" />
414
415 </div>
416
417 <div class="form-group">
418 <label for="exampleInputEmail1">Correo</label>
419 <input th:field="*{correo}" type="email" class="form-control" id="exampleInputEmail1" placeholder="Email" />
420
421 </div>
422
423 <div class="form-group">
424 <label for="">Distrito</label>
425 <select th:field="*{distrito}" class="form-control">
426 <option th:each="distrito: ${distritoEditado}" th:value="${distrito.id}" th:text="${distrito.nombre}"></option>
427
428 </select>
429 </div>
430 <div class="form-group">
431 <label for="">Universidad</label>
432 <select th:field="*{universidad}" class="form-control">
433 <option th:each="universidad: ${universidadEditado}" th:value="${universidad.id}" th:text="${universidad.nombre}"></option>
434
435 </select>
436 </div>
437
438
439 <div class="form-group">
440 <label for="">Genero</label>
441
442 <div class="radio">
443 <label>
444 <input th:field="*{genero}" type="radio" name="optionsRadios" id="optionsRadios2" value="2" />
445 femenino
446 </label>
447 </div>
448 <div class="radio">
449 <label>
450 <input th:field="*{genero}" type="radio" name="optionsRadios" id="optionsRadios2" value="1" />
451 masculino
452 </label>
453 </div>
454
455 </div>
456
457 <button type="submit" class="btn btn-default">Guardar</button>
458 </form>
459
460Lateral...
461<body>
462 <div class="container-fluid" th:fragment="menu_lateral">
463 <div class="col-sm-3 col-md-2 sidebar">
464 <ul class="nav nav-list">
465 <li class="nav-header">Alumnos</li>
466 <li><a href="/admin/persona/listado">listar alumnos</a></li>
467 <li><a href="/admin/persona/nuevo">nuevo alumno</a></li>
468 </ul>
469
470 <ul class="nav nav-list">
471 <li class="nav-header">Menú 02</li>
472 <li><a href="">Opción 01</a></li>
473 <li><a href="">Opción 02</a></li>
474 </ul>
475 </div>
476 </div>
477 </body>
478
479
480CREATE DATABASE IF NOT EXISTS `practica02` /*!40100 DEFAULT CHARACTER SET utf8 */;
481USE `practica02`;
482-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
483--
484-- Host: localhost Database: practica02
485-- ------------------------------------------------------
486-- Server version 5.7.17-log
487
488/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
489/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
490/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
491/*!40101 SET NAMES utf8 */;
492/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
493/*!40103 SET TIME_ZONE='+00:00' */;
494/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
495/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
496/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
497/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
498
499--
500-- Table structure for table `distritos`
501--
502
503DROP TABLE IF EXISTS `distritos`;
504/*!40101 SET @saved_cs_client = @@character_set_client */;
505/*!40101 SET character_set_client = utf8 */;
506CREATE TABLE `distritos` (
507 `id` int(11) NOT NULL AUTO_INCREMENT,
508 `nombre` varchar(45) DEFAULT NULL,
509 PRIMARY KEY (`id`)
510) ENGINE=InnoDB DEFAULT CHARSET=utf8;
511/*!40101 SET character_set_client = @saved_cs_client */;
512
513--
514-- Dumping data for table `distritos`
515--
516
517LOCK TABLES `distritos` WRITE;
518/*!40000 ALTER TABLE `distritos` DISABLE KEYS */;
519/*!40000 ALTER TABLE `distritos` ENABLE KEYS */;
520UNLOCK TABLES;
521
522--
523-- Table structure for table `personas`
524--
525
526DROP TABLE IF EXISTS `personas`;
527/*!40101 SET @saved_cs_client = @@character_set_client */;
528/*!40101 SET character_set_client = utf8 */;
529CREATE TABLE `personas` (
530 `id` int(11) NOT NULL AUTO_INCREMENT,
531 `nombres` varchar(45) DEFAULT NULL,
532 `apellidos` varchar(45) DEFAULT NULL,
533 `correo` varchar(45) DEFAULT NULL,
534 `distrito_id` int(11) DEFAULT NULL,
535 `universidad_id` int(11) DEFAULT NULL,
536 `genero` tinyint(4) DEFAULT NULL,
537 PRIMARY KEY (`id`)
538) ENGINE=InnoDB DEFAULT CHARSET=utf8;
539/*!40101 SET character_set_client = @saved_cs_client */;
540
541--
542-- Dumping data for table `personas`
543--
544
545LOCK TABLES `personas` WRITE;
546/*!40000 ALTER TABLE `personas` DISABLE KEYS */;
547/*!40000 ALTER TABLE `personas` ENABLE KEYS */;
548UNLOCK TABLES;
549
550--
551-- Table structure for table `universidades`
552--
553
554DROP TABLE IF EXISTS `universidades`;
555/*!40101 SET @saved_cs_client = @@character_set_client */;
556/*!40101 SET character_set_client = utf8 */;
557CREATE TABLE `universidades` (
558 `id` int(11) NOT NULL AUTO_INCREMENT,
559 `nombre` varchar(45) DEFAULT NULL,
560 PRIMARY KEY (`id`)
561) ENGINE=InnoDB DEFAULT CHARSET=utf8;
562/*!40101 SET character_set_client = @saved_cs_client */;
563
564--
565-- Dumping data for table `universidades`
566--
567
568LOCK TABLES `universidades` WRITE;
569/*!40000 ALTER TABLE `universidades` DISABLE KEYS */;
570/*!40000 ALTER TABLE `universidades` ENABLE KEYS */;
571UNLOCK TABLES;
572/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
573
574/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
575/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
576/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
577/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
578/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
579/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
580/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
581
582-- Dump completed on 2017-11-04 7:07:47
583
584
585
586
587
588
589
590CREATE DATABASE IF NOT EXISTS `libreriavirtual` /*!40100 DEFAULT CHARACTER SET utf8 */;
591USE `libreriavirtual`;
592-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
593--
594-- Host: localhost Database: libreriavirtual
595-- ------------------------------------------------------
596-- Server version 5.7.17-log
597
598/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
599/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
600/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
601/*!40101 SET NAMES utf8 */;
602/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
603/*!40103 SET TIME_ZONE='+00:00' */;
604/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
605/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
606/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
607/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
608
609--
610-- Table structure for table `administradores`
611--
612
613DROP TABLE IF EXISTS `administradores`;
614/*!40101 SET @saved_cs_client = @@character_set_client */;
615/*!40101 SET character_set_client = utf8 */;
616CREATE TABLE `administradores` (
617 `id` int(11) NOT NULL AUTO_INCREMENT,
618 `nombres` varchar(75) DEFAULT NULL,
619 `apellidos` varchar(75) DEFAULT NULL,
620 `correo` varchar(75) DEFAULT NULL,
621 `clave` varchar(75) DEFAULT NULL,
622 `rol_id` int(11) DEFAULT NULL,
623 `estado` tinyint(4) DEFAULT NULL,
624 PRIMARY KEY (`id`),
625 KEY `fk_roles_idx` (`rol_id`),
626 CONSTRAINT `fk_roles` FOREIGN KEY (`rol_id`) REFERENCES `roles` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
627) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
628/*!40101 SET character_set_client = @saved_cs_client */;
629
630--
631-- Dumping data for table `administradores`
632--
633
634LOCK TABLES `administradores` WRITE;
635/*!40000 ALTER TABLE `administradores` DISABLE KEYS */;
636INSERT INTO `administradores` VALUES (1,'Juan','Perez','juan@correo.com','123',1,1),(7,'Usuario02','Apellidos02','correo2@correo.com','$2a$10$hKKwEyrwXsRnFqxlenxoNeDTn2K5Ci8QKN03SNQcawoXYnTKK/oty',1,1),(8,'NombreCliente01','ApellidoCliente01','cliente@correo.com','$2a$10$hKKwEyrwXsRnFqxlenxoNeDTn2K5Ci8QKN03SNQcawoXYnTKK/oty',2,1);
637/*!40000 ALTER TABLE `administradores` ENABLE KEYS */;
638UNLOCK TABLES;
639
640--
641-- Table structure for table `autores`
642--
643
644DROP TABLE IF EXISTS `autores`;
645/*!40101 SET @saved_cs_client = @@character_set_client */;
646/*!40101 SET character_set_client = utf8 */;
647CREATE TABLE `autores` (
648 `id` int(11) NOT NULL AUTO_INCREMENT,
649 `nombres` varchar(75) NOT NULL,
650 `apellidos` varchar(75) NOT NULL,
651 `nacionalidad` varchar(100) DEFAULT NULL,
652 PRIMARY KEY (`id`)
653) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
654/*!40101 SET character_set_client = @saved_cs_client */;
655
656--
657-- Dumping data for table `autores`
658--
659
660LOCK TABLES `autores` WRITE;
661/*!40000 ALTER TABLE `autores` DISABLE KEYS */;
662INSERT INTO `autores` VALUES (1,'Nombre 01','Apellido 01','Nacionalidad 01'),(2,'Nombre 02','Apellido 021','Nacionalidad 05222'),(3,'Nombre 03','Apellido 031','Nacionalidad 031'),(4,'Autor nombre 01','Apellido nombre 01','Peruana');
663/*!40000 ALTER TABLE `autores` ENABLE KEYS */;
664UNLOCK TABLES;
665
666--
667-- Table structure for table `editoriales`
668--
669
670DROP TABLE IF EXISTS `editoriales`;
671/*!40101 SET @saved_cs_client = @@character_set_client */;
672/*!40101 SET character_set_client = utf8 */;
673CREATE TABLE `editoriales` (
674 `id` int(11) NOT NULL AUTO_INCREMENT,
675 `nombre` varchar(45) DEFAULT NULL,
676 PRIMARY KEY (`id`)
677) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
678/*!40101 SET character_set_client = @saved_cs_client */;
679
680--
681-- Dumping data for table `editoriales`
682--
683
684LOCK TABLES `editoriales` WRITE;
685/*!40000 ALTER TABLE `editoriales` DISABLE KEYS */;
686INSERT INTO `editoriales` VALUES (1,'Editorial 01'),(2,'Editorial 02'),(3,'Editorial 03'),(4,'Editorial 04'),(5,'Editorial 05');
687/*!40000 ALTER TABLE `editoriales` ENABLE KEYS */;
688UNLOCK TABLES;
689
690--
691-- Table structure for table `generos`
692--
693
694DROP TABLE IF EXISTS `generos`;
695/*!40101 SET @saved_cs_client = @@character_set_client */;
696/*!40101 SET character_set_client = utf8 */;
697CREATE TABLE `generos` (
698 `id` int(11) NOT NULL AUTO_INCREMENT,
699 `nombre` varchar(45) DEFAULT NULL,
700 PRIMARY KEY (`id`)
701) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
702/*!40101 SET character_set_client = @saved_cs_client */;
703
704--
705-- Dumping data for table `generos`
706--
707
708LOCK TABLES `generos` WRITE;
709/*!40000 ALTER TABLE `generos` DISABLE KEYS */;
710INSERT INTO `generos` VALUES (1,'Terror'),(2,'Comedia'),(3,'Suspenso'),(4,'Acción');
711/*!40000 ALTER TABLE `generos` ENABLE KEYS */;
712UNLOCK TABLES;
713
714--
715-- Table structure for table `libro_autor`
716--
717
718DROP TABLE IF EXISTS `libro_autor`;
719/*!40101 SET @saved_cs_client = @@character_set_client */;
720/*!40101 SET character_set_client = utf8 */;
721CREATE TABLE `libro_autor` (
722 `libro_id` int(11) NOT NULL,
723 `autor_id` int(11) NOT NULL,
724 PRIMARY KEY (`libro_id`,`autor_id`),
725 KEY `fk_autor_idx` (`autor_id`),
726 CONSTRAINT `fk_autor` FOREIGN KEY (`autor_id`) REFERENCES `autores` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
727 CONSTRAINT `fk_libro` FOREIGN KEY (`libro_id`) REFERENCES `libros` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
728) ENGINE=InnoDB DEFAULT CHARSET=utf8;
729/*!40101 SET character_set_client = @saved_cs_client */;
730
731--
732-- Dumping data for table `libro_autor`
733--
734
735LOCK TABLES `libro_autor` WRITE;
736/*!40000 ALTER TABLE `libro_autor` DISABLE KEYS */;
737INSERT INTO `libro_autor` VALUES (4,1),(10,1),(3,2),(4,2),(10,2),(3,3),(4,3);
738/*!40000 ALTER TABLE `libro_autor` ENABLE KEYS */;
739UNLOCK TABLES;
740
741--
742-- Table structure for table `libros`
743--
744
745DROP TABLE IF EXISTS `libros`;
746/*!40101 SET @saved_cs_client = @@character_set_client */;
747/*!40101 SET character_set_client = utf8 */;
748CREATE TABLE `libros` (
749 `id` int(11) NOT NULL AUTO_INCREMENT,
750 `genero_id` int(11) DEFAULT NULL,
751 `editorial_id` int(11) DEFAULT NULL,
752 `titulo` varchar(75) DEFAULT NULL,
753 `precio` decimal(6,2) DEFAULT NULL,
754 `isbn` varchar(20) DEFAULT NULL,
755 `sinopsis` varchar(300) DEFAULT NULL,
756 `nuevo` tinyint(1) DEFAULT NULL,
757 PRIMARY KEY (`id`),
758 KEY `fk_genero_idx` (`genero_id`),
759 KEY `fk_editorial_idx` (`editorial_id`),
760 CONSTRAINT `fk_editorial` FOREIGN KEY (`editorial_id`) REFERENCES `editoriales` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
761 CONSTRAINT `fk_genero` FOREIGN KEY (`genero_id`) REFERENCES `generos` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
762) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
763/*!40101 SET character_set_client = @saved_cs_client */;
764
765--
766-- Dumping data for table `libros`
767--
768
769LOCK TABLES `libros` WRITE;
770/*!40000 ALTER TABLE `libros` DISABLE KEYS */;
771INSERT INTO `libros` VALUES (1,2,3,'titulo 01',20.00,'456-92-2','sinopsis 01',1),(2,1,1,'titulo 02',20.00,'456-92-2','qqqq',1),(3,3,4,'titulo 03',20.00,'456-92-2','aaaaaaa',1),(4,2,4,'titulo 04',60.00,'456-92-7','qqqqcccccc',1),(5,3,3,'libro11',50.00,'2115-5654-2','qqqqqqqqqqq',0),(6,3,3,'libro12',50.00,'2115-5654-2','qqqqqqqqqqq',0),(7,3,3,'libro12',50.00,'2115-5654-2','qqqqqqqqqqq',0),(8,3,3,'libro12',50.00,'2115-5654-2','qqqqqqqqqqq',1),(10,3,2,'libro15',50.00,'456-92-2','qqqqq',0);
772/*!40000 ALTER TABLE `libros` ENABLE KEYS */;
773UNLOCK TABLES;
774
775--
776-- Table structure for table `roles`
777--
778
779DROP TABLE IF EXISTS `roles`;
780/*!40101 SET @saved_cs_client = @@character_set_client */;
781/*!40101 SET character_set_client = utf8 */;
782CREATE TABLE `roles` (
783 `id` int(11) NOT NULL AUTO_INCREMENT,
784 `nombre` varchar(45) DEFAULT NULL,
785 `estado` tinyint(4) DEFAULT NULL,
786 PRIMARY KEY (`id`)
787) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
788/*!40101 SET character_set_client = @saved_cs_client */;
789
790--
791-- Dumping data for table `roles`
792--
793
794LOCK TABLES `roles` WRITE;
795/*!40000 ALTER TABLE `roles` DISABLE KEYS */;
796INSERT INTO `roles` VALUES (1,'Admin',1),(2,'Usuario',1),(3,'Operador',1);
797/*!40000 ALTER TABLE `roles` ENABLE KEYS */;
798UNLOCK TABLES;
799/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
800
801/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
802/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
803/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
804/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
805/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
806/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
807/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
808
809-- Dump completed on 2017-11-21 19:57:34