<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rails y más cosas &#187; spring</title>
	<atom:link href="http://www.railsymas.com/category/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsymas.com</link>
	<description>Nuevas Tecnologías</description>
	<lastBuildDate>Sat, 28 Jan 2012 10:23:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spring mvc uno a muchos hibernate</title>
		<link>http://www.railsymas.com/2012/01/02/spring-mvc-uno-a-muchos-hibernate/</link>
		<comments>http://www.railsymas.com/2012/01/02/spring-mvc-uno-a-muchos-hibernate/#comments</comments>
		<pubDate>Mon, 02 Jan 2012 17:56:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2578</guid>
		<description><![CDATA[Siguiendo con los ejemplos de spring framework con hibernate en este caso establecemos una relación uno a muchos con jpa La siguiente imagen corresponde a una vista jsp donde tenemos una llamada a la acción que desencadena el ejemplo Creamos la interface Unoamuchos que nos servirá de esqueleto para nuestra aplicación 1 2 3 4 [...]]]></description>
			<content:encoded><![CDATA[<p>Siguiendo con los ejemplos de spring framework con hibernate en este caso establecemos una relación uno a muchos con jpa</p>
<p><span id="more-2578"></span></p>
<p>La siguiente imagen corresponde a una vista jsp donde tenemos una llamada a la acción que desencadena el ejemplo</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2012/01/unoam1.png" alt="" title="unoam1" width="317" height="30" class="alignnone size-full wp-image-2579" /></p>
<p>Creamos la interface Unoamuchos que nos servirá de esqueleto para nuestra aplicación</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Propietario</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Automovil</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Unoamuchos <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Propietario<span style="color: #339933;">&gt;</span> listadoPropietarios<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Automovil<span style="color: #339933;">&gt;</span>  listadoAutomoviles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> introducirPropietario <span style="color: #009900;">&#40;</span>Propietario propietario<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Implementación de la interface</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Automovil</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Propietario</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.orm.hibernate3.HibernateTemplate</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UnoamuchosImpl <span style="color: #000000; font-weight: bold;">implements</span> Unoamuchos <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">private</span> HibernateTemplate hibernateTemplate<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> HibernateTemplate getHibernateTemplate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> hibernateTemplate<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHibernateTemplate<span style="color: #009900;">&#40;</span>HibernateTemplate hibernateTemplate<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">hibernateTemplate</span> <span style="color: #339933;">=</span> hibernateTemplate<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Propietario<span style="color: #339933;">&gt;</span> listadoPropietarios<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Propietario<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> hibernateTemplate.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Propietario&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Automovil<span style="color: #339933;">&gt;</span> listadoAutomoviles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
		  	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Automovil<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> hibernateTemplate.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Automovil&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> introducirPropietario <span style="color: #009900;">&#40;</span>Propietario propietario<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			hibernateTemplate.<span style="color: #006633;">saveOrUpdate</span><span style="color: #009900;">&#40;</span>propietario<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Imagen del formulario de entrada de datos</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2012/01/unoam2.png" alt="" title="unoam2" width="623" height="361" class="alignnone size-full wp-image-2591" /></p>
<p>Listado de datos una vez introducidos<br />
<img src="http://www.railsymas.com/wp-content/uploads/2012/01/unoam3.png" alt="" title="unoam3" width="632" height="303" class="alignnone size-full wp-image-2593" /></p>
<p>Configuración del bean de gestión</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/formulariopropietario.html&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;controlador.ControladorPropietario&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;methodNameResolver&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;paramResolver&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;propieatarioDao&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;propietarioDao&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Controlador encargado de la gestión</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">controlador</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.ModelAndView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.mvc.multiaction.MultiActionController</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.ui.ModelMap</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ClasesBean.DatosPropietario</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Unoamuchos</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Propietario</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Automovil</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ControladorPropietario <span style="color: #000000; font-weight: bold;">extends</span> MultiActionController <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Unoamuchos	propieatarioDao<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Automovil<span style="color: #339933;">&gt;</span> listaautomoviles <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span> <span style="color: #339933;">&lt;</span>Automovil<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Unoamuchos getPropieatarioDao<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> propieatarioDao<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setPropieatarioDao<span style="color: #009900;">&#40;</span>Unoamuchos propieatarioDao<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">propieatarioDao</span> <span style="color: #339933;">=</span> propieatarioDao<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ModelAndView introducirDatos <span style="color: #009900;">&#40;</span> HttpServletRequest request, HttpServletResponse response, DatosPropietario propietario<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		Propietario owner <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Propietario<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Automovil automovil <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Automovil<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		automovil.<span style="color: #006633;">setMarca</span><span style="color: #009900;">&#40;</span>propietario.<span style="color: #006633;">getMarca</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		automovil.<span style="color: #006633;">setModelo</span><span style="color: #009900;">&#40;</span>propietario.<span style="color: #006633;">getModelo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		owner.<span style="color: #006633;">setNombre</span><span style="color: #009900;">&#40;</span>propietario.<span style="color: #006633;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		owner.<span style="color: #006633;">setApellidos</span><span style="color: #009900;">&#40;</span>propietario.<span style="color: #006633;">getApellidos</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		listaautomoviles.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>automovil<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		owner.<span style="color: #006633;">setPropietarioautomovil</span><span style="color: #009900;">&#40;</span>listaautomoviles<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        propieatarioDao.<span style="color: #006633;">introducirPropietario</span><span style="color: #009900;">&#40;</span>owner<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    	ModelMap mapa <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ModelMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	mapa.<span style="color: #006633;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;propietarios&quot;</span>,propieatarioDao.<span style="color: #006633;">listadoPropietarios</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	mapa.<span style="color: #006633;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;automoviles&quot;</span>,propieatarioDao.<span style="color: #006633;">listadoAutomoviles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	ModelAndView vista <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resultadopropietario&quot;</span>,mapa<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #000000; font-weight: bold;">return</span> vista<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ModelAndView introducirPropietario <span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response, DatosPropietario propietario<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
		ModelAndView vista <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;formulariopropietario&quot;</span>,<span style="color: #0000ff;">&quot;propietario&quot;</span>,propietario<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> vista<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase modelo propietario</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">modelos</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.CascadeType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GenerationType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Table</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Column</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GeneratedValue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Id</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.OneToMany</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.JoinTable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.JoinColumn</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
@<span style="color: #003399;">Entity</span>
@Table <span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;propietario&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Propietario <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> propietarioid<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> apellidos<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Automovil<span style="color: #339933;">&gt;</span> propietarioautomovil<span style="color: #339933;">;</span>
&nbsp;
	@Id
	@GeneratedValue<span style="color: #009900;">&#40;</span>strategy<span style="color: #339933;">=</span>GenerationType.<span style="color: #006633;">IDENTITY</span><span style="color: #009900;">&#41;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;propietario_id&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">long</span> getPropietarioid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> propietarioid<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setPropietarioid<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> propietarioid<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">propietarioid</span> <span style="color: #339933;">=</span> propietarioid<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nombre&quot;</span>, nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>, length<span style="color: #339933;">=</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getNombre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setNombre<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> nombre<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nombre</span> <span style="color: #339933;">=</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;apellidos&quot;</span>,nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getApellidos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> apellidos<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setApellidos<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> apellidos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">apellidos</span> <span style="color: #339933;">=</span> apellidos<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@OneToMany<span style="color: #009900;">&#40;</span>cascade <span style="color: #339933;">=</span> CascadeType.<span style="color: #006633;">ALL</span><span style="color: #009900;">&#41;</span>
	@JoinTable<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;propietario_automovil&quot;</span>, joinColumns <span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span>@JoinColumn <span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;propietario_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>, inverseJoinColumns<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span>@JoinColumn <span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;automovil_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Automovil<span style="color: #339933;">&gt;</span> getPropietarioautomovil<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> propietarioautomovil<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setPropietarioautomovil<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Automovil<span style="color: #339933;">&gt;</span> propietarioautomovil<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">propietarioautomovil</span> <span style="color: #339933;">=</span> propietarioautomovil<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase modelo Automovil</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">modelos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Column</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GeneratedValue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GenerationType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Id</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Table</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;automovil&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Automovil <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> automovilid<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> marca<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> modelo<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    @Id
    @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">IDENTITY</span><span style="color: #009900;">&#41;</span>
    @Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;automovil_id&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getAutomovilid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> automovilid<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAutomovilid<span style="color: #009900;">&#40;</span><span style="color: #003399;">Long</span> automovilid<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">automovilid</span> <span style="color: #339933;">=</span> automovilid<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;marca&quot;</span>,nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMarca<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> marca<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMarca<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> marca<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">marca</span> <span style="color: #339933;">=</span> marca<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;modelo&quot;</span>,nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getModelo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> modelo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setModelo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> modelo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">modelo</span> <span style="color: #339933;">=</span> modelo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Configuración de la factoria en dispatcher-servlet.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;conexionFactoria&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;annotatedClasses&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modelos.Propietario<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modelos.Automovil<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><img src="http://www.railsymas.com/wp-content/uploads/2012/01/unoam5.png" alt="" title="unoam5" width="186" height="41" class="alignnone size-full wp-image-2599" /><br />
<img src="http://www.railsymas.com/wp-content/uploads/2012/01/unoam4.png" alt="" title="unoam4" width="726" height="101" class="alignnone size-full wp-image-2601" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2012/01/02/spring-mvc-uno-a-muchos-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integración plantillas velocity Spring framework</title>
		<link>http://www.railsymas.com/2011/12/28/integracion-plantillas-velocity-spring-framework-eg/</link>
		<comments>http://www.railsymas.com/2011/12/28/integracion-plantillas-velocity-spring-framework-eg/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 17:23:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1645</guid>
		<description><![CDATA[En anteriores post ya se habían expuesto tanto la forma de descargar el proyecto velocity como las características generales de cómo trabajar con velocity. Para facilitar el trabajo con platillas velocity habíamos recomendado un plugin para el editor eclipse llamado veloeclipse Ahora en este post vemos la forma de integrarlo en uno de los frameworks [...]]]></description>
			<content:encoded><![CDATA[<p> En anteriores post ya se habían expuesto tanto la forma de descargar el proyecto velocity como las características generales de cómo trabajar con velocity. </p>
<p> Para facilitar el trabajo con platillas velocity habíamos recomendado un plugin para el editor eclipse<br />
 llamado veloeclipse</p>
<p> Ahora en este post vemos la forma de integrarlo en uno de los frameworks más importantes de java como es spring framework. Spring nos ofrece un importante soporte para dichas plantillas facilitando su integración</p>
<p><span id="more-1645"></span></p>
<p>Simplemente el ejercicio que se muestra es una forma alternativa de mostrar los resultados al igual que hacíamos con spring mvc mostrando las vistas con jsp normales</p>
<p>Para ello vamos a configurar el motor de velocity para spring, crearemos dentro del fichero de configuración de spring en nuestro caso, dispatcher-servlet.xml un bean velocityconfigurer aunque el nombre del bean es opcional lo ponemos para acordarnos de que estamos creando una configuración para velocity</p>
<p>Dentro del bean velocityConfigurer tenemos una propiedad resourceLoaderPath con el valor WEB-INF/plantillasvelocity . Con esto estamos configurando el motor de plantillas velocity y le decimos a velocity donde encontrar las plantillas.</p>
<p>Una vez hecho lo anterior debemos de configurar la resolución de visualización para velocity<br />
para ello creamos un bean nombre viewResolver de clase VelecityViewResolver y declaramos la propiedad suffix con el valo .vm</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;viewResolver&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.velocity.VelocityViewResolver&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;suffix&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;.vm&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;velocityConfigurer&quot;</span>       <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.velocity.VelocityConfigurer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;resourceLoaderPath&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/plantillasvelocity&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Código para la página ejercicios.vm</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Ejercicios<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span>Ejercicios<span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
	        <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
             <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;basico.html&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> Trabajo b<span style="color: #339933;">&amp;</span>aacute<span style="color: #339933;">;</span>sico con plantillas<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;objetos.html&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> Trabajo con objetos  <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>visualización de ejercicios.vm</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/12/basico1.png" alt="" title="basico1" width="629" height="168" class="alignnone size-full wp-image-2565" /></p>
<p>Simplemente en ejercicios tenemos dos enlaces a dos acciones, la diferencia que se puede apreciar con respecto a jsp es que no hemos declarado ninguna librería</p>
<p>En este ejemplo básico se accede a una platilla en la que se muestra el mensaje almacenado en un bean de configuración</p>
<p>Código de básico.vm</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>basico<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  $<span style="color: #009900;">&#123;</span>mensajeporpantalla<span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Visualización de la plantilla básico.vm</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/12/basico2.png" alt="" title="basico2" width="626" height="78" class="alignnone size-full wp-image-2573" /></p>
<p>Dentro del fichero de configuración dispatcher-servlet.xml se declara el bean basico.html asociado al controlador con el nombre basico en el package controlador y una propieadad mensaje con el valor hola plantillas velocity que será lo que salga por pantalla</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/basico.html&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;controlador.Basico&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mensaje&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;hola plantilas velocity&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Código del controlador Basico.java</p>
<p>Simplemente generamos un setter para la propiedad mensaje y mediante ModelAndView cargamos los datos en la vista con el valor del string mensajeporpantalla</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">controlador</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.ModelAndView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.mvc.AbstractController</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Basico  <span style="color: #000000; font-weight: bold;">extends</span> AbstractController
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> mensaje<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ModelAndView handleRequestInternal <span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;basico&quot;</span>,<span style="color: #0000ff;">&quot;mensajeporpantalla&quot;</span>,<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mensaje</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setMensaje<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> mensaje<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">mensaje</span> <span style="color: #339933;">=</span> mensaje<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En otro ejemplo más complejo se verán el tratamiento de objetos y formularios</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/12/28/integracion-plantillas-velocity-spring-framework-eg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exportando los datos a pdf con spring framework</title>
		<link>http://www.railsymas.com/2011/10/31/exportando-los-datos-a-pdf-con-spring-framework/</link>
		<comments>http://www.railsymas.com/2011/10/31/exportando-los-datos-a-pdf-con-spring-framework/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 16:20:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2494</guid>
		<description><![CDATA[En el anterior post habíamos visto para la categoría de spring framework un ejemplo de relación uno a uno con hibernate donde teníamos la posibilidad de además de almacenar los datos exportarlos a excel En el siguiente ejemplo vamos a exportar esos mismos datos a formato pdf Datos introducidos para un estudiante laura, maria y [...]]]></description>
			<content:encoded><![CDATA[<p> En el anterior post habíamos visto para la categoría de spring framework un ejemplo de relación uno a uno con hibernate donde teníamos la posibilidad de además de almacenar los datos exportarlos a excel</p>
<p><span id="more-2494"></span></p>
<p> En el siguiente ejemplo vamos a exportar esos mismos datos a formato pdf</p>
<p> Datos introducidos para un estudiante laura, maria y juan</p>
<p> <img src="http://www.railsymas.com/wp-content/uploads/2011/10/spdf1.png" alt="" title="spdf1" width="617" height="357" class="alignnone size-full wp-image-2512" /></p>
<p> Visualización de datos </p>
<p> <img src="http://www.railsymas.com/wp-content/uploads/2011/10/spdf2.png" alt="" title="spdf2" width="609" height="399" class="alignnone size-full wp-image-2514" /></p>
<p>Pulsamos sobre el icono de fichero pdf</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/10/spdf3.png" alt="" title="spdf3" width="600" height="421" class="alignnone size-full wp-image-2516" /></p>
<p> Código de la clase de recursos</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletOutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.view.document.AbstractPdfView</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.lowagie.text.Document</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.lowagie.text.Element</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.lowagie.text.pdf.PdfWriter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.lowagie.text.pdf.PdfPTable</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.lowagie.text.pdf.PdfPCell</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Estudiante</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Direccion</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ByteArrayOutputStream</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.lowagie.text.Paragraph</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.Color</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GenerarPdf  <span style="color: #000000; font-weight: bold;">extends</span> AbstractPdfView <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">ByteArrayOutputStream</span> fichero <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> buildPdfDocument <span style="color: #009900;">&#40;</span> <span style="color: #003399;">Map</span> model, <span style="color: #003399;">Document</span> document, PdfWriter pdfwriter,HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>  
&nbsp;
		List<span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> estudiantes <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> model.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;estudiantes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		List<span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> direcciones <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> model.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;direcciones&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
		document.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		PdfPTable tablaestudiantes <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfPTable<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		PdfPCell celdanombre <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfPCell<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Paragraph<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		PdfPCell celdaedad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfPCell<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Paragraph<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;edad&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		PdfPCell tituloestudiantes <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfPCell<span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Paragraph<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;listado estudiantes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		tituloestudiantes.<span style="color: #006633;">setColspan</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		tituloestudiantes.<span style="color: #006633;">setBackgroundColor</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">214</span>,<span style="color: #cc66cc;">246</span>,<span style="color: #cc66cc;">145</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		tituloestudiantes.<span style="color: #006633;">setHorizontalAlignment</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span>.<span style="color: #006633;">ALIGN_CENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		celdanombre.<span style="color: #006633;">setHorizontalAlignment</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span>.<span style="color: #006633;">ALIGN_CENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		celdanombre.<span style="color: #006633;">setBackgroundColor</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">217</span>,<span style="color: #cc66cc;">217</span>,<span style="color: #cc66cc;">180</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		celdaedad.<span style="color: #006633;">setHorizontalAlignment</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span>.<span style="color: #006633;">ALIGN_CENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		celdaedad.<span style="color: #006633;">setBackgroundColor</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">217</span>,<span style="color: #cc66cc;">217</span>,<span style="color: #cc66cc;">180</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		tablaestudiantes.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>tituloestudiantes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		tablaestudiantes.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>celdanombre<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		tablaestudiantes.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>celdaedad<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> Iterator<span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> iterador <span style="color: #339933;">=</span>  estudiantes.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> iterador.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span>
	    <span style="color: #009900;">&#123;</span>
	    	Estudiante estudiante <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Estudiante<span style="color: #009900;">&#41;</span> iterador.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	tablaestudiantes.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>estudiante.<span style="color: #006633;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	tablaestudiantes.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>estudiante.<span style="color: #006633;">getEdad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	    document.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tablaestudiantes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    document.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Paragraph<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;                                         &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    PdfPTable tabladirecciones <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> PdfPTable<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	    PdfPCell celdacalle<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfPCell<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Paragraph<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;calle&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		PdfPCell celdalocalidad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfPCell<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Paragraph<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localidad&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		PdfPCell titulodirecciones <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PdfPCell<span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Paragraph<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;listado direcciones&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		titulodirecciones.<span style="color: #006633;">setColspan</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		titulodirecciones.<span style="color: #006633;">setBackgroundColor</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">214</span>,<span style="color: #cc66cc;">246</span>,<span style="color: #cc66cc;">145</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		titulodirecciones.<span style="color: #006633;">setHorizontalAlignment</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span>.<span style="color: #006633;">ALIGN_CENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		celdacalle.<span style="color: #006633;">setBackgroundColor</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">217</span>,<span style="color: #cc66cc;">217</span>,<span style="color: #cc66cc;">180</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		celdacalle.<span style="color: #006633;">setHorizontalAlignment</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span>.<span style="color: #006633;">ALIGN_CENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		celdalocalidad.<span style="color: #006633;">setBackgroundColor</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">217</span>,<span style="color: #cc66cc;">217</span>,<span style="color: #cc66cc;">180</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		celdalocalidad.<span style="color: #006633;">setHorizontalAlignment</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span>.<span style="color: #006633;">ALIGN_CENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		tabladirecciones.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>titulodirecciones<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        tabladirecciones.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>celdacalle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        tabladirecciones.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>celdalocalidad<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> Iterator<span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> iterador <span style="color: #339933;">=</span>  direcciones.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> iterador.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span>
	    <span style="color: #009900;">&#123;</span>
	    	Direccion direccion <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Direccion<span style="color: #009900;">&#41;</span> iterador.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	tabladirecciones.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>direccion.<span style="color: #006633;">getCalle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	tabladirecciones.<span style="color: #006633;">addCell</span><span style="color: #009900;">&#40;</span>direccion.<span style="color: #006633;">getLocalidad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span>
&nbsp;
	    document.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tabladirecciones<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    document.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	    response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    response.<span style="color: #006633;">setContentLength</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fichero</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-disposition&quot;</span>,<span style="color: #0000ff;">&quot;attachment; filename=estudiantes.pdf&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    ServletOutputStream out <span style="color: #339933;">=</span> response.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fichero</span>.<span style="color: #006633;">writeTo</span><span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    out.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> llamandoBuildPdf<span style="color: #009900;">&#40;</span>Map<span style="color: #339933;">&lt;</span>String,List<span style="color: #339933;">&gt;</span> model,HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
	   <span style="color: #003399;">Document</span> document <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Document</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	   document.<span style="color: #006633;">addTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;listado estudiantes hibernate &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	   PdfWriter aux  <span style="color: #339933;">=</span>	PdfWriter.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>document,<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fichero</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	   buildPdfDocument <span style="color: #009900;">&#40;</span>model,document,aux, request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Gracias al controlador que lo hemos declarado como multiactioncontroller podemos realizar múltiples acciones en un mismo fichero de clase permitiéndonos introducir los datos en la base de datos así como exportarlos tanto a excel como a pdf</p>
<p>Modificamos la vista del formulario de estudiantes del anterior ejemplo para ello creamos un menú para tener las dos opciones disponibles </p>
<p>css encargada del menú</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">ul<span style="color: #00AA00;">&#123;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
&nbsp;
 <span style="color: #00AA00;">&#125;</span>
&nbsp;
 ul li <span style="color: #00AA00;">&#123;</span> 
  <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
 <span style="color: #00AA00;">&#125;</span>  
&nbsp;
 <span style="color: #cc00cc;">#enlacepdf</span> a<span style="color: #00AA00;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;../imagenes/file_pdf.png&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #00AA00;">&#125;</span>
&nbsp;
 <span style="color: #cc00cc;">#enlaceexcel</span> a <span style="color: #00AA00;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;../imagenes/file_excel.png&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
 <span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
 <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
 <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">55px</span><span style="color: #00AA00;">;</span>
 <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">55px</span><span style="color: #00AA00;">;</span>
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Dentro del controlador estudiante añadimos el método</p>
<p>generarPdf</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> generarPdf<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
      List<span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> estudiantes <span style="color: #339933;">=</span> estudianteDao.<span style="color: #006633;">listadoEstudiantes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      List<span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> direcciones <span style="color: #339933;">=</span> estudianteDao.<span style="color: #006633;">listadoDireccion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003399;">Map</span> modelmap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashMap</span> <span style="color: #339933;">&lt;</span>String,List<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      modelmap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;estudiantes&quot;</span>, estudiantes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      modelmap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;direcciones&quot;</span>, direcciones<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      
&nbsp;
      GenerarPdf pdf <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GenerarPdf<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      pdf.<span style="color: #006633;">llamandoBuildPdf</span><span style="color: #009900;">&#40;</span>modelmap, request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Cambiamos el código de la página para poder visualizar el menú</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span> 
    pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags/form&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span>
 <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unoanuno.resultado&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>ul id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;menu&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enlacepdf&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;c:url value='formularioestudiante.html?method=generarPdf'/&gt;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enlaceexcel&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;c:url value='formularioestudiante.html?method=generarExcel'/&gt;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;borrar&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&amp;</span>nbsp<span style="color: #339933;">;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de  estudiantes&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tabla&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>table title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de estudiantes&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>nombre<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>edad<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span> 
 <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${estudiantes}&quot;</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;estudiante&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span>  <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${estudiante.nombre}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;</span>  <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${estudiante.edad}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de direcciones&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tabla&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>table title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de direcciones&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>calle<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>localidad<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span> 
 <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${direcciones}&quot;</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;direccion&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span> 
 <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${direccion.calle}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${direccion.localidad}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span> 
 <span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;c:url value=&quot;</span><span style="color: #339933;">/</span>ejercicios.<span style="color: #006633;">html</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">&gt;</span>Regreso a ejercicios<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p> Resultado </p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/10/spdf4.png" alt="" title="spdf4" width="697" height="458" class="alignnone size-full wp-image-2518" /></p>
<p>Al igual que en el ejemplo de excel en este ejemplo para el desarrollo de spring mvc pdf e hibernate no es el objetivo un tutorial sobre la librería itext por ello para mayor entendimiento y más ejemplos se deriva a la siguiente dirección web para completar conocimientos</p>
<p><a href="http://www.roseindia.net/java/itext/index.shtml">Rose India</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/10/31/exportando-los-datos-a-pdf-con-spring-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exportando datos a excel con spring framework</title>
		<link>http://www.railsymas.com/2011/10/26/exportando-datos-a-excel-con-spring-framework/</link>
		<comments>http://www.railsymas.com/2011/10/26/exportando-datos-a-excel-con-spring-framework/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 15:27:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2460</guid>
		<description><![CDATA[Habíamos visto la inserción de datos mediante jdbcTemplate de spring y luego un ejemplo sobre hibernate en una relación de uno a uno En la primera imagen podemos observar un formulario para introducir los datos estará controlado por hibernate Código del formulario de introducción de datos del estudiante &#8220;formularioestudiante.jsp&#8221; 1 2 3 4 5 6 [...]]]></description>
			<content:encoded><![CDATA[<p>Habíamos visto la inserción de datos mediante jdbcTemplate de spring y luego un ejemplo sobre hibernate en una relación de uno a uno</p>
<p><span id="more-2460"></span></p>
<p> En la primera imagen podemos observar un formulario para introducir los datos estará controlado por hibernate</p>
<p> <img src="http://www.railsymas.com/wp-content/uploads/2011/10/hiberex1.png" alt="" title="hiberex1" width="612" height="376" class="alignnone size-full wp-image-2462" /></p>
<p>Código del formulario de introducción de datos del estudiante &#8220;formularioestudiante.jsp&#8221;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span>  pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags/form&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&quot;</span><span style="color: #339933;">%&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unoauno.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span> <span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unoauno.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>h2<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formularioestudiante.html&quot;</span>  method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> commandName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;datosestudiante&quot;</span><span style="color: #339933;">&gt;</span> 
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unoauno.nombre&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unoauno.edad&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;edad&quot;</span><span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unoauno.calle&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;calle&quot;</span><span style="color: #339933;">/&gt;</span> 
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unoauno.localidad&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;localidad&quot;</span><span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
   <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;method&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;introducirDatos&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
&nbsp;
   <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>En el formulario llamamos al método introducirDatos</p>
<p>Mensajes utilizados en las vistas de los ficheros jsp dentro del fichero messages_es_xx.properties</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">unoauno.titulo = formulario uno a uno spring hibernate
unoauno.nombre = Introduce tu nombre:
unoauno.edad =  Introduce tu edad:
unoauno.calle = Introduce la tu calle:
unoauno.localidad = Intoduce tu localidad:
&nbsp;
unoanuno.resultado = Listados estudiantes y direcciones</pre></td></tr></table></div>

<p>En la siguiente imagen se muestra al usuario seleccionando un icono para lanzar la acción<br />
de creación del fichero excel</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/10/hiberex2.png" alt="" title="hiberex2" width="612" height="301" class="alignnone size-full wp-image-2463" /></p>
<p>Códigio del formulario resultadoestudiante.jsp</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span> 
    pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags/form&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span>
 <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unoanuno.resultado&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enlaceexcel&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;c:url value=&quot;</span>formularioestudiante.<span style="color: #006633;">html</span><span style="color: #339933;">?</span>method<span style="color: #339933;">=</span>generarExcel<span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;borrar&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&amp;</span>nbsp<span style="color: #339933;">;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de  estudiantes&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tabla&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>table title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de estudiantes&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>nombre<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>edad<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span> 
 <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${estudiantes}&quot;</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;estudiante&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span>  <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${estudiante.nombre}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;</span>  <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${estudiante.edad}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de direcciones&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tabla&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>table title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de direcciones&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>calle<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>localidad<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span> 
 <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${direcciones}&quot;</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;direccion&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span> 
 <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${direccion.calle}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${direccion.localidad}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span> 
 <span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;c:url value=&quot;</span><span style="color: #339933;">/</span>ejercicios.<span style="color: #006633;">html</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">&gt;</span>Regreso a ejercicios<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>En la siguiente imagen se muestra la pantalla contextual de creación del fichero excel estudiante para guardar o visualizar</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/10/hiberex3.png" alt="" title="hiberex3" width="658" height="368" class="alignnone size-full wp-image-2464" /></p>
<p>Una vez abierto el fichero excel se visualizan los datos cargados</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/10/hiberex4.png" alt="" title="hiberex4" width="529" height="234" class="alignnone size-full wp-image-2465" /></p>
<p>Basándonos en el ejemplo  <a href="http://www.railsymas.com/2011/07/25/spring-framework-mvc-hibernate-uno-a-uno/">hibernate uno a uno </a></p>
<p>Una vez arrancado nuestro proyecto en la realización del ejemplo en el navegador tendríamos<br />
urlproyecto\formularioestudiante.html?method=introducirEstudiante</p>
<p>El bean encargado de recoger la acción declarado en el fichero de configuración dispatcher-servlet.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;template&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.HibernateTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;conexionFactoria&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;estudianteDao&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;recursos.UnoaunoImpl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernateTemplate&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;template&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/formularioestudiante.html&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;controlador.ControladorEstudiante&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;methodNameResolver&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;paramResolver&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;estudianteDao&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;estudianteDao&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>La propiedad estudianteDao nos permite trabajar con una sesión factoria, el controlador estudiante recibe la petición para ser tratada.</p>
<p>Código controlador estudiante</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">controlador</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.ModelAndView</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.mvc.multiaction.MultiActionController</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ClasesBean.DatosEstudiante</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Direccion</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Estudiante</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Unoauno</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.ui.ModelMap</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashMap</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.GenerarExcel</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ControladorEstudiante <span style="color: #000000; font-weight: bold;">extends</span> MultiActionController 
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Unoauno estudianteDao<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Unoauno getEstudianteDao<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> estudianteDao<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setEstudianteDao<span style="color: #009900;">&#40;</span>Unoauno estudianteDao<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">estudianteDao</span> <span style="color: #339933;">=</span> estudianteDao<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> ModelAndView introducirDatos <span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response, DatosEstudiante datosestudiante<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
    	Direccion direccion <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Direccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	Estudiante estudiante <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Estudiante<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	direccion.<span style="color: #006633;">setCalle</span><span style="color: #009900;">&#40;</span>datosestudiante.<span style="color: #006633;">getCalle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	direccion.<span style="color: #006633;">setLocalidad</span><span style="color: #009900;">&#40;</span>datosestudiante.<span style="color: #006633;">getLocalidad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	estudiante.<span style="color: #006633;">setNombre</span><span style="color: #009900;">&#40;</span>datosestudiante.<span style="color: #006633;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	estudiante.<span style="color: #006633;">setEdad</span><span style="color: #009900;">&#40;</span>datosestudiante.<span style="color: #006633;">getEdad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	estudiante.<span style="color: #006633;">setEstudiantedireccion</span><span style="color: #009900;">&#40;</span>direccion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	estudianteDao.<span style="color: #006633;">introducirEstudiante</span><span style="color: #009900;">&#40;</span>estudiante<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
    	ModelMap mapa <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ModelMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	mapa.<span style="color: #006633;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;estudiantes&quot;</span>,estudianteDao.<span style="color: #006633;">listadoEstudiantes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	mapa.<span style="color: #006633;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;direcciones&quot;</span>,estudianteDao.<span style="color: #006633;">listadoDireccion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	ModelAndView vista <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resultadoestudiante&quot;</span>,mapa<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #000000; font-weight: bold;">return</span> vista<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> generarExcel <span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
    <span style="color: #009900;">&#123;</span>
    	List<span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> estudiantes <span style="color: #339933;">=</span> estudianteDao.<span style="color: #006633;">listadoEstudiantes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	List<span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> direcciones <span style="color: #339933;">=</span> estudianteDao.<span style="color: #006633;">listadoDireccion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #003399;">Map</span> modelmap <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashMap</span> <span style="color: #339933;">&lt;</span>String,List<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	modelmap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;estudiantes&quot;</span>, estudiantes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	modelmap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;direcciones&quot;</span>,direcciones<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	GenerarExcel excel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> GenerarExcel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	excel.<span style="color: #006633;">llamandoBuildExcelDocument</span><span style="color: #009900;">&#40;</span>request, response, modelmap<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;generar excel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ModelAndView introducirEstudiante <span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response, DatosEstudiante datosestudiante<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
	  	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;formularioestudiante&quot;</span>,<span style="color: #0000ff;">&quot;datosestudiante&quot;</span>,datosestudiante<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>La clase controlador estudiante extiende de multiactionController que ya habíamos visto su funcionamiento en un post anterior</p>
<p><a href="http://www.railsymas.com/2011/03/24/formulario-multiactioncontroller-spring-framework/">ejemplo de multiactionController</a></p>
<p>una vez que introducimos los datos en el sistema de bases de datos mediante hibernate mostramos la vista resultadoestudiante.jsp</p>
<p>Dentro del package recursos tenemos la clase encargada de generar el fichero excel</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletOutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.poi.hssf.usermodel.HSSFWorkbook</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.poi.hssf.usermodel.HSSFSheet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.poi.hssf.usermodel.HSSFCellStyle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.poi.hssf.usermodel.HSSFRow</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Estudiante</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Direccion</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.view.document.AbstractExcelView</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.ByteArrayOutputStream</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GenerarExcel  <span style="color: #000000; font-weight: bold;">extends</span> AbstractExcelView
<span style="color: #009900;">&#123;</span>   
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">ByteArrayOutputStream</span> fichero <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ByteArrayOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> numerofilas<span style="color: #339933;">;</span> 
&nbsp;
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;deprecation&quot;</span><span style="color: #009900;">&#41;</span>
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> buildExcelDocument<span style="color: #009900;">&#40;</span><span style="color: #003399;">Map</span> model, HSSFWorkbook libro ,
			HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> 
    <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
		<span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> estudiantes <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> model.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;estudiantes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> direcciones <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> model.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;direcciones&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		HSSFCellStyle estilo <span style="color: #339933;">=</span> libro.<span style="color: #006633;">createCellStyle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">//creación de una hoja</span>
		HSSFSheet hoja <span style="color: #339933;">=</span> libro.<span style="color: #006633;">createSheet</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;libro estudiantes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">//creamos la fila cabecera</span>
		HSSFRow fila0 <span style="color: #339933;">=</span>  hoja.<span style="color: #006633;">createRow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		fila0.<span style="color: #006633;">createCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCellValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		fila0.<span style="color: #006633;">createCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCellValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;edad&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">numerofilas</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Iterator</span> iterador <span style="color: #339933;">=</span> estudiantes.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> iterador.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			Estudiante estudiante <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Estudiante<span style="color: #009900;">&#41;</span> iterador.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			HSSFRow fila <span style="color: #339933;">=</span> hoja.<span style="color: #006633;">createRow</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">numerofilas</span> <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			fila.<span style="color: #006633;">createCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCellValue</span><span style="color: #009900;">&#40;</span>estudiante.<span style="color: #006633;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			fila.<span style="color: #006633;">createCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCellValue</span><span style="color: #009900;">&#40;</span>estudiante.<span style="color: #006633;">getEdad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
		   libro.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>fichero<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		   fichero.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		   response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/vnd.ms-excel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    response.<span style="color: #006633;">setContentLength</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fichero</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    response.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-disposition&quot;</span>,<span style="color: #0000ff;">&quot;attachment; filename=estudiantes.xls&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    ServletOutputStream out <span style="color: #339933;">=</span> response.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fichero</span>.<span style="color: #006633;">writeTo</span><span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    out.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>  
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> llamandoBuildExcelDocument <span style="color: #009900;">&#40;</span> HttpServletRequest request, HttpServletResponse response, <span style="color: #003399;">Map</span> model<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>   
&nbsp;
		<span style="color: #666666; font-style: italic;">//creamos el libro</span>
		HSSFWorkbook libro <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HSSFWorkbook <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
		buildExcelDocument<span style="color: #009900;">&#40;</span>model,libro,request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase dentro del package de recursos unoauno.java</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Direccion</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Estudiante</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Unoauno <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> introducirEstudiante<span style="color: #009900;">&#40;</span>Estudiante estudiante<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> listadoEstudiantes <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> listadoDireccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase encargada de la implementación de la interface Unoauno</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Direccion</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Estudiante</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.orm.hibernate3.HibernateTemplate</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UnoaunoImpl <span style="color: #000000; font-weight: bold;">implements</span> Unoauno
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> HibernateTemplate hibernateTemplate<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> HibernateTemplate getHibernateTemplate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> hibernateTemplate<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHibernateTemplate<span style="color: #009900;">&#40;</span>HibernateTemplate hibernateTemplate<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">hibernateTemplate</span> <span style="color: #339933;">=</span> hibernateTemplate<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> listadoEstudiantes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> hibernateTemplate.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Estudiante&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> listadoDireccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	  	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> hibernateTemplate.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Direccion&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> introducirEstudiante <span style="color: #009900;">&#40;</span>Estudiante estudiante<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		hibernateTemplate.<span style="color: #006633;">saveOrUpdate</span><span style="color: #009900;">&#40;</span>estudiante<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>El objetivo del ejemplo era crear la interconexión entre diferentes tecnologías para llegar a una situación cotidiana a nivel de empresa pero sin pretender ser un estudio exaustivo en la introducción de liberías para excel en java por ello introducimos un enlace a un sitio donde amplian información </p>
<p><a href="http://www.roseindia.net/answers/viewqa/Java-Beginners/14883-how-to-use-Excel-Templet-to-write-excel-file-using-java..html">Rose India</a></p>
<p>Se intenta simpre evitar poner cosas que no esten en español pero en este caso por las ventajas que suponen para el lector se pone un enlace a una web en inglés pero hay que decir que es sencillo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/10/26/exportando-datos-a-excel-con-spring-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>spring framework mvc hibernate uno a uno</title>
		<link>http://www.railsymas.com/2011/07/25/spring-framework-mvc-hibernate-uno-a-uno/</link>
		<comments>http://www.railsymas.com/2011/07/25/spring-framework-mvc-hibernate-uno-a-uno/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 18:21:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2421</guid>
		<description><![CDATA[Siguiendo con los ejemplos desarrollados sobre spring mvc para la getión de bases de datos creamos un ejemplo para una relación del tipo uno a uno Formulario para la introducción de datos Resultado de los datos introducidos En este ejemplo aparecen dos clases implicadas estudiantes y dirección 1 2 3 4 5 6 7 8 [...]]]></description>
			<content:encoded><![CDATA[<p> Siguiendo con los ejemplos desarrollados sobre spring mvc para la getión de bases de datos creamos un ejemplo para una relación del tipo uno a uno</p>
<p> <span id="more-2421"></span></p>
<p> Formulario para la introducción de datos </p>
<p> <img src="http://www.railsymas.com/wp-content/uploads/2011/07/formulariouno1.png" alt="" title="formulariouno1" width="609" height="354" class="alignnone size-full wp-image-2424" /></p>
<p> Resultado de los datos introducidos</p>
<p> <img src="http://www.railsymas.com/wp-content/uploads/2011/07/resultadounoauno.png" alt="" title="resultadounoauno" width="614" height="307" class="alignnone size-full wp-image-2428" /></p>
<p>En este ejemplo aparecen dos clases implicadas estudiantes y dirección</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/07/modelspr.png" alt="" title="modelspr" width="226" height="188" class="alignnone size-full wp-image-2435" /></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">modelos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Column</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GeneratedValue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GenerationType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Id</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Table</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;direccion&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Direccion <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> calle<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> localidad<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	@Id
	@GeneratedValue<span style="color: #009900;">&#40;</span>strategy<span style="color: #339933;">=</span>GenerationType.<span style="color: #006633;">IDENTITY</span><span style="color: #009900;">&#41;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;direccion_id&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> getDireccion_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> direccion_id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDireccion_id<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> direccionId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		direccion_id <span style="color: #339933;">=</span> direccionId<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;calle&quot;</span>,nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getCalle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> calle<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setCalle<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> calle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">calle</span> <span style="color: #339933;">=</span> calle<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;localidad&quot;</span>,nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLocalidad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> localidad<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLocalidad<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> localidad<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">localidad</span> <span style="color: #339933;">=</span> localidad<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">modelos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Column</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GeneratedValue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GenerationType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Id</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Table</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;direccion&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Direccion <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> direccion_id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> calle<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> localidad<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	@Id
	@GeneratedValue<span style="color: #009900;">&#40;</span>strategy<span style="color: #339933;">=</span>GenerationType.<span style="color: #006633;">IDENTITY</span><span style="color: #009900;">&#41;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;direccion_id&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Integer</span> getDireccion_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> direccion_id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDireccion_id<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> direccionId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		direccion_id <span style="color: #339933;">=</span> direccionId<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;calle&quot;</span>,nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getCalle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> calle<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setCalle<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> calle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">calle</span> <span style="color: #339933;">=</span> calle<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;localidad&quot;</span>,nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>,length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLocalidad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> localidad<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLocalidad<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> localidad<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">localidad</span> <span style="color: #339933;">=</span> localidad<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Direccion</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Estudiante</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Unoauno <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> introducirEstudiante<span style="color: #009900;">&#40;</span>Estudiante estudiante<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> listadoEstudiantes <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> listadoDireccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Direccion</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Estudiante</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.orm.hibernate3.HibernateTemplate</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UnoaunoImpl <span style="color: #000000; font-weight: bold;">implements</span> Unoauno
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> HibernateTemplate hibernateTemplate<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> HibernateTemplate getHibernateTemplate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> hibernateTemplate<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHibernateTemplate<span style="color: #009900;">&#40;</span>HibernateTemplate hibernateTemplate<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">hibernateTemplate</span> <span style="color: #339933;">=</span> hibernateTemplate<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span> listadoEstudiantes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Estudiante<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> hibernateTemplate.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Estudiante&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span> listadoDireccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	  	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Direccion<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> hibernateTemplate.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Direccion&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> introducirEstudiante <span style="color: #009900;">&#40;</span>Estudiante estudiante<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		hibernateTemplate.<span style="color: #006633;">saveOrUpdate</span><span style="color: #009900;">&#40;</span>estudiante<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/07/25/spring-framework-mvc-hibernate-uno-a-uno/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ejemplo Spring framework mvc hibernate</title>
		<link>http://www.railsymas.com/2011/07/06/ejemplo-spring-framework-mvc-hibernate/</link>
		<comments>http://www.railsymas.com/2011/07/06/ejemplo-spring-framework-mvc-hibernate/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 21:37:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2376</guid>
		<description><![CDATA[En anteriores post habíamos creado ejemplos de conexión de bases de datos con spring mvc con jdbc introduciendo dos formas de desarrollo una de ellas permitía el uso de interface para spring reduciendo el tiempo de creación de métodos de acceso a bases de datos. La utilización de una herramienta orm para la capa de [...]]]></description>
			<content:encoded><![CDATA[<p>En anteriores post habíamos creado ejemplos de conexión de bases de datos con spring mvc con jdbc introduciendo dos formas de desarrollo una de ellas permitía el uso de interface para spring reduciendo el tiempo de creación de métodos de acceso a bases de datos.</p>
<p><span id="more-2376"></span></p>
<p>La utilización de una herramienta orm para la capa de persistencia puede ahorrar muchas líneas de código. Permitiendo concentrarse en los requisitos de la aplicación en lugar de escribir código sql extenso que puede provocar errores</p>
<p>Spring es compatible con varios marcos de trabajo orm entre los cuales se incluyen hibernate, ibatis, ojb, jdo, toplink.</p>
<p>El soporte del marco spring sobre hibernate se encuentra en el paquete org.springframework.orm.hibernate para la version hibernate2. Para la versión 3 de hibernate se encuenta en org.springfremework.orm.hibernate3</p>
<p>El marco spring permite el trabajo con archivos de mapeo xml de hibernate, donde tenemos un fichero hbm.xml y crear un bean de factoria de spring LocalSessionFactoryBean que produce una instancia local de SessionFactory que es la responsable de abrir y cerrar sesiones de hibernate.</p>
<p>La segunda posibilidad que ofrece el marco de spring para el trabajo de hibernate consiste en las anotaciones. El marco spring mediante AnnotationSessionFactoryBean crea un SessionFactory basado en anotaciones de clases de dominio.</p>
<p>Se crea por tanto una serie de clases de dominio anotadas para luego mediante AnnotationSessionBean factory crear una SessionFactory que permite el trabajo apertura, cierre y tratamiento de hibernate</p>
<p>Tenemos la propiedad datasource que corresponde a la referencia de una fuente de datos previamente creada en el archivo de configuración de spring como habíamos visto con jdbc spring, la propiedad annotatedClasses sirve para declarar la lista de clases anotadas. Por último la propieadad hibernateProperties permite declarar la configuración de hibernate donde lo más importante es la daclaración del dialecto a utilizar</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;conexionFactoria&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;annotatedClasses&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modelos.Libros<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernateProperties&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.dialect&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>org.hibernate.dialect.MySQL5Dialect<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.hbm2ddl.auto&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>update<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;hibernate.show_sql&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;template&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.orm.hibernate3.HibernateTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;conexionFactoria&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;libroDao&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;recursos.LibrosImpl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernateTemplate&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;template&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Código de la clase bean Libros clase con anotaciones</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">modelos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GenerationType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Table</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Column</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GeneratedValue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Id</span><span style="color: #339933;">;</span>
&nbsp;
@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libros&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Libros 
<span style="color: #009900;">&#123;</span>   
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> titulo<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> autor<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> tematica<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Libros<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Id
	@GeneratedValue<span style="color: #009900;">&#40;</span>strategy<span style="color: #339933;">=</span>GenerationType.<span style="color: #006633;">IDENTITY</span><span style="color: #009900;">&#41;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #003399;">Long</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
    @Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo&quot;</span>, nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>, length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTitulo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> titulo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTitulo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> titulo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">titulo</span> <span style="color: #339933;">=</span> titulo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;autor&quot;</span>, nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>, length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getAutor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> autor<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAutor<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> autor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">autor</span> <span style="color: #339933;">=</span> autor<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	@Column<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tematica&quot;</span>, nullable<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>, length<span style="color: #339933;">=</span><span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTematica<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> tematica<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTematica<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> tematica<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tematica</span> <span style="color: #339933;">=</span> tematica<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En el ejemplo utilizamos jpa por el hecho de que en los frameworks jee de nueva generación la utilización de jpa es muy importante y así se van asentando los conceptos teóricos.</p>
<p>Jpa es un estándar para hacer mapeo objeto relacional permitiendo hacer el acceso a los datos de la base de datos mediante el uso de objetos que se declaran como persistentes.Jpa facilita el desarrollo de aplicaciones reduciendo el número de instrucciones para el tratamiento de los datos almacenados.</p>
<p>Jpa utiliza anotaciones par indicar que las clases son persistentes y establecer el mapeo entre clases y tablas. En jpa una clase persistente es una entidad, es por tanto una clase cuyas entidades de graban en la base de datos</p>
<p>Se utiliza @Entity para definir una clase como persistente, @Table para definir la tabla de la base de datos. Una entidad tiene una serie de propiedades y esas propiedades son semajentes a una clase de java. Las propiedades son persistentes y asume que existen como campos en la tabla. Si se quiere que una propiedad no sea persistente anteponemos @transient </p>
<p>@Column para especificar nombres, tipos y longitudes de campos de tablas. @Id para identificar la clave</p>
<p>Si hubiesemos optado por el modelo clásico de hibernate tendríamos un fichero xml de la siguiente forma</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE hibernate-mapping PUBLIC</span>
<span style="color: #00bbdd;">	&quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;</span>
<span style="color: #00bbdd;">	&quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;modelos.Libros&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;libros&quot;</span> <span style="color: #000066;">catalog</span>=<span style="color: #ff0000;">&quot;libros_jdbc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.Integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;identity&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;autor&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;autor&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tematica&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tematica&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Tenemos la configuración para la base de datos libros_jdbc al igual que habíamos visto en los ejemplos de jdbctemplate</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.commons.dbcp.BasicDataSource&quot;</span> <span style="color: #000066;">destroy-method</span>=<span style="color: #ff0000;">&quot;close&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost:3306/libros_jdbc&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Clases para la gestión del modelo madiante la implementación de la interface Libros</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Libros</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Interfaceslibros <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> guardarLibro <span style="color: #009900;">&#40;</span>Libros libro<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Libros<span style="color: #339933;">&gt;</span> listadoLibros <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.orm.hibernate3.HibernateTemplate</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Libros</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LibrosImpl <span style="color: #000000; font-weight: bold;">implements</span>  Interfaceslibros
<span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> HibernateTemplate hibernateTemplate<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> HibernateTemplate getHibernateTemplate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> hibernateTemplate<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setHibernateTemplate<span style="color: #009900;">&#40;</span>HibernateTemplate hibernateTemplate<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">hibernateTemplate</span> <span style="color: #339933;">=</span> hibernateTemplate<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> guardarLibro <span style="color: #009900;">&#40;</span>Libros libro<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
		hibernateTemplate.<span style="color: #006633;">saveOrUpdate</span><span style="color: #009900;">&#40;</span>libro<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>Libros<span style="color: #339933;">&gt;</span> listadoLibros<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>Libros<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> hibernateTemplate.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Libros&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Código del controlador, utilizamos una clase que extiende de multiactioncontroler que habíamos visto en anteriores post <a href="http://www.railsymas.com/2011/03/24/formulario-multiactioncontroller-spring-framework/">formulario multiactioncontroller</a>. Esta clase nos permite guardar libros e insertar libros.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">controlador</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.ModelAndView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.mvc.multiaction.MultiActionController</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.Libros</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Interfaceslibros</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ControladorHibernateLibros <span style="color: #000000; font-weight: bold;">extends</span> MultiActionController
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Interfaceslibros daolibros<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDaolibros<span style="color: #009900;">&#40;</span>Interfaceslibros daolibros<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">daolibros</span> <span style="color: #339933;">=</span> daolibros<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ModelAndView guardarLibro <span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response, Libros libro<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>   
		daolibros.<span style="color: #006633;">guardarLibro</span><span style="color: #009900;">&#40;</span>libro<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		ModelAndView vista <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resultadolibros&quot;</span>,<span style="color: #0000ff;">&quot;listado&quot;</span>,daolibros.<span style="color: #006633;">listadoLibros</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> vista<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ModelAndView insertarLibro <span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response,Libros libros<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>
	  	ModelAndView vista <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;formulariolibroshibernate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    vista.<span style="color: #006633;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;libros&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> Libros<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">return</span> vista<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>insertamos los datos correspondientes a los libros<br />
<img src="http://www.railsymas.com/wp-content/uploads/2011/07/autorhi.png" alt="" title="autorhi" width="610" height="303" class="alignnone size-full wp-image-2397" /></p>
<p>Código correspondiente a las páginas jsp formularioslibroshibernate</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span> pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags/form&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;librohibernate.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;librohibernate.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>h2<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formulariolibroshibernate.html&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> commandName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libros&quot;</span><span style="color: #339933;">&gt;</span> 
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.titulolibro&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.autorlibro&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;autor&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.tematicalibro&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tematica&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;method&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;guardarLibro&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span> 
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>configuración de la vista formulariolibroshibernate</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/formulariolibroshibernate.html&quot;</span>    <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;controlador.ControladorHibernateLibros&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;methodNameResolver&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;paramResolver&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;daolibros&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;libroDao&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>resultado de la introducción de datos<br />
<img src="http://www.railsymas.com/wp-content/uploads/2011/07/hiberdos.png" alt="" title="hiberdos" width="606" height="160" class="alignnone size-full wp-image-2399" /></p>
<p>Código correspondiente a la salida por pantalla de los datos</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=ISO-8859-1&quot;</span>     pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ISO-8859-1&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=ISO-8859-1&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;resultadojdbc.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;resultadojdbc.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>h2<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tabla&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>table title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de libros&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>titulo<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>autor<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>tematica<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${listado}&quot;</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libro&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${libro.titulo}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${libro.autor}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span> 
     <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${libro.tematica}&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span> www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span> <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/07/06/ejemplo-spring-framework-mvc-hibernate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Aplicación web flow jdbc spring framework 2º parte</title>
		<link>http://www.railsymas.com/2011/07/02/aplicacion-web-flow-jdbc-spring-framework-2%c2%ba-parte/</link>
		<comments>http://www.railsymas.com/2011/07/02/aplicacion-web-flow-jdbc-spring-framework-2%c2%ba-parte/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 19:05:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2336</guid>
		<description><![CDATA[Siguiendo el ejemplo anterior en el que se declaraban una serie de estados que integraban la aplicación de web flow para el framework spring. En la primera parte del ejemplo habíamos creado el fichero de configuración con los estados correspondientes al flujo enlace ejemplo-de-aplicacion-para-spring-web-flow Funcionamiento de la aplicación tenemos una serie de usuarios creados en [...]]]></description>
			<content:encoded><![CDATA[<p>Siguiendo el ejemplo anterior en el que se declaraban una serie de estados que integraban la aplicación de web flow para el framework spring. </p>
<p>En la primera parte del ejemplo habíamos creado el fichero de configuración con los estados correspondientes al flujo enlace <a href="http://www.railsymas.com/2011/04/19/ejemplo-de-aplicacion-para-spring-web-flow/">ejemplo-de-aplicacion-para-spring-web-flow</a></p>
<p><span id="more-2336"></span></p>
<p>Funcionamiento de la aplicación tenemos una serie de usuarios creados en la base de datos, es tarea de la aplicación reconocer dichos usuarios introducciendo el número de teléfono. Si dicho teléfono introducido en la primera pantalla corresponde con un cliente (usuario de la base de dastos) entonces se pasa directamente a una pantalla con sus datos y puede realizar la compra de unos productos. En caso de no ser reconocido el número de teléfono se le pasa a una pantalla con donde debe registrarse para luego acceder a la de compra una vez registrado</p>
<p>En este ejemplo estamos utilizando el manipulador de mapeo SimpeUrlHandlerMapping, este manipulador ayuda al dispatcherServlet a elegir qué controlador enviar la petición</p>
<p>Permite mapear patrones url directamente a controladores para ellos dentro de la propiedasdes del bean ulMapping declaramos el patrón ul dentro de la clave key y luego el valor de la propiedad sería el nombre del controlador en este caso flowController ya que es el utilizado para web flow pero podemos declarar más como por ejemplo (ejercicios) que es un controlador creado por el programador</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;urlMapping&quot;</span></span>
<span style="color: #009900;">     <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mappings&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;/aplicacion.html&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>flowController<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;/hola.html&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>flowController<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prop</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;/ejercicios.html&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>ejercicios<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/prop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/props<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Tenemos tres clases que son las encargadas de gestionar el flujo de la aplicación</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/07/flows1.png" alt="" title="flows1" width="252" height="91" class="alignnone size-full wp-image-2347" /></p>
<p>recordamos que tenemos un fichero xml de configuración donde vienen los estados declarados</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/07/flows2.png" alt="" title="flows2" width="306" height="101" class="alignnone size-full wp-image-2353" /></p>
<p>Tabla correspodiente a clientes </p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/07/flowtabla1.png" alt="" title="flowtabla1" width="366" height="186" class="alignnone size-full wp-image-2359" /></p>
<p>Tabla correspodiente a pedidos</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/07/flowtabla2.png" alt="" title="flowtabla2" width="479" height="181" class="alignnone size-full wp-image-2360" /></p>
<p>Partiendo de los anteriores datos almacenados en las tablas, entramos en la aplicación con el teléfono de pedro <img src="http://www.railsymas.com/wp-content/uploads/2011/07/imgflow1.png" alt="" title="imgflow1" width="616" height="204" class="alignnone size-full wp-image-2363" /></p>
<p>Al ser un usuario reconocido de la base de datos accedemos a la ficha para adquisición de un producto<br />
<img src="http://www.railsymas.com/wp-content/uploads/2011/07/imgflow2.png" alt="" title="imgflow2" width="623" height="410" class="alignnone size-full wp-image-2364" /></p>
<p>Mostramos el resultado final<br />
<img src="http://www.railsymas.com/wp-content/uploads/2011/07/imgflow3.png" alt="" title="imgflow3" width="622" height="218" class="alignnone size-full wp-image-2365" /></p>
<p>Segundo caso un usuario no existente en la base de datos introduce un número de teléfono<br />
<img src="http://www.railsymas.com/wp-content/uploads/2011/07/img4flow.png" alt="" title="img4flow" width="616" height="206" class="alignnone size-full wp-image-2367" /></p>
<p>Aparece una pantalla donde tiene que registrase introduciendo su nombre y su número de teléfono de nuevo<br />
<img src="http://www.railsymas.com/wp-content/uploads/2011/07/img2flow.png" alt="" title="img2flow" width="608" height="198" class="alignnone size-full wp-image-2371" /></p>
<p>Pasamos a la pantalla donde el cliente puede elegir los productos a comprar<br />
<img src="http://www.railsymas.com/wp-content/uploads/2011/07/img3flow.png" alt="" title="img3flow" width="604" height="407" class="alignnone size-full wp-image-2373" /></p>
<p>Pantalla final con el resultado final de la compra</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/07/img4flow1.png" alt="" title="img4flow" width="612" height="215" class="alignnone size-full wp-image-2374" /></p>
<p>Código de la clase ClienteAplicacion.java</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">actionflows</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Cliente</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Producto</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ClasesBean.Pedido</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.ConexionCliente</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.sql.DataSource</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.Action</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.Event</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.RequestContext</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ClienteAplicacion <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Action</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> DataSource conexion<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> ConexionCliente clienteBases<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span>  ClienteAplicacion <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	clienteBases <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span>  ConexionCliente<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DataSource getConexion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> conexion<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setConexion<span style="color: #009900;">&#40;</span>DataSource conexion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span> <span style="color: #339933;">=</span> conexion<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clienteBases</span>.<span style="color: #006633;">setConexion</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Event</span> execute<span style="color: #009900;">&#40;</span>RequestContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
		<span style="color: #003399;">Event</span> evento<span style="color: #339933;">;</span>
	    Pedido pedido<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #003399;">String</span> telefono <span style="color: #339933;">=</span> context.<span style="color: #006633;">getRequestParameters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;telefono&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Cliente cliente <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clienteBases</span>.<span style="color: #006633;">buscarCliente</span><span style="color: #009900;">&#40;</span>telefono<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">//insertamos el cliente al pedido</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cliente <span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
&nbsp;
		    pedido <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Pedido<span style="color: #009900;">&#41;</span> context.<span style="color: #006633;">getFlowScope</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pedido&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    pedido.<span style="color: #006633;">setCliente</span><span style="color: #009900;">&#40;</span>cliente<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			evento <span style="color: #339933;">=</span>	<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Event</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>,<span style="color: #0000ff;">&quot;encontrado&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			evento <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Event</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>,<span style="color: #0000ff;">&quot;vacio&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> evento<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase GestionPedido</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">actionflows</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Producto</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ClasesBean.Pedido</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.ConexionCliente</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.sql.DataSource</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.Action</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.Event</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.RequestContext</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GestionPedido <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Action</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> DataSource conexion<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> ConexionCliente clienteBases<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span>  GestionPedido <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	clienteBases <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span>  ConexionCliente<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DataSource getConexion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> conexion<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setConexion<span style="color: #009900;">&#40;</span>DataSource conexion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span> <span style="color: #339933;">=</span> conexion<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clienteBases</span>.<span style="color: #006633;">setConexion</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> CalculoTotal <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> unidades , <span style="color: #003399;">String</span> nombre,Producto producto<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">float</span> total <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nombre.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;telefono&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			producto.<span style="color: #006633;">setPrecio</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			total <span style="color: #339933;">=</span> unidades <span style="color: #339933;">*</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nombre.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;televisor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			producto.<span style="color: #006633;">setPrecio</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			total <span style="color: #339933;">=</span> unidades <span style="color: #339933;">*</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nombre.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;frigorifico&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>  
			producto.<span style="color: #006633;">setPrecio</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">450</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			total <span style="color: #339933;">=</span> unidades <span style="color: #339933;">*</span> <span style="color: #cc66cc;">450</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> total<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Event</span> execute<span style="color: #009900;">&#40;</span>RequestContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	    Pedido pedido<span style="color: #339933;">;</span>
&nbsp;
		pedido <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Pedido<span style="color: #009900;">&#41;</span> context.<span style="color: #006633;">getFlowScope</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pedido&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		Producto  producto <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Producto<span style="color: #009900;">&#41;</span> pedido.<span style="color: #006633;">getProducto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		pedido.<span style="color: #006633;">setImporte</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">CalculoTotal</span><span style="color: #009900;">&#40;</span>producto.<span style="color: #006633;">getUnidades</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,producto.<span style="color: #006633;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,producto<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> posicion <span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clienteBases</span>.<span style="color: #006633;">encontrarCliente</span><span style="color: #009900;">&#40;</span>pedido.<span style="color: #006633;">getCliente</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTelefono</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		pedido.<span style="color: #006633;">getCliente</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span>posicion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clienteBases</span>.<span style="color: #006633;">insertarPedido</span><span style="color: #009900;">&#40;</span>pedido<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Event</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>,<span style="color: #0000ff;">&quot;satisfactorio&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase RegistroCliente.java</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">actionflows</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.Action</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.Event</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.webflow.execution.RequestContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.sql.DataSource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.ConexionCliente</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Cliente</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ClasesBean.Pedido</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RegistroCliente <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Action</span> 
<span style="color: #009900;">&#123;</span>  
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> DataSource conexion<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> ConexionCliente clienteBases<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> RegistroCliente <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
	  clienteBases <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span>  ConexionCliente<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> DataSource getConexion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">return</span> conexion<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setConexion<span style="color: #009900;">&#40;</span>DataSource conexion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span> <span style="color: #339933;">=</span> conexion<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clienteBases</span>.<span style="color: #006633;">setConexion</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Event</span> execute<span style="color: #009900;">&#40;</span>RequestContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
  <span style="color: #009900;">&#123;</span>
	   <span style="color: #003399;">Event</span> evento<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	  Pedido pedido <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Pedido<span style="color: #009900;">&#41;</span> context.<span style="color: #006633;">getFlowScope</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pedido&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	  Cliente cliente <span style="color: #339933;">=</span> pedido.<span style="color: #006633;">getCliente</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	  <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">clienteBases</span>.<span style="color: #006633;">insertarCliente</span><span style="color: #009900;">&#40;</span>cliente<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	  evento <span style="color: #339933;">=</span>  <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Event</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>,<span style="color: #0000ff;">&quot;satisfactorio&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	   <span style="color: #000000; font-weight: bold;">return</span> evento<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Código correspondiente a las clases de recursos</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">ClasesBean</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Cliente</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Producto</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Pedido <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * 
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Cliente cliente<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Producto producto<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">float</span> importe<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">float</span> getImporte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> importe<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setImporte<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> importe<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">importe</span> <span style="color: #339933;">=</span> importe<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Pedido<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cliente</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Cliente<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">producto</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Producto<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Producto getProducto<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> producto<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setProducto<span style="color: #009900;">&#40;</span>Producto producto<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">producto</span> <span style="color: #339933;">=</span> producto<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Cliente getCliente<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> cliente<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setCliente<span style="color: #009900;">&#40;</span>Cliente cliente<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cliente</span> <span style="color: #339933;">=</span> cliente<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Código de las clases de recursos</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Cliente <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * 
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> telefono<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getNombre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setNombre<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> nombre<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nombre</span> <span style="color: #339933;">=</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTelefono<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> telefono<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTelefono<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> telefono<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">telefono</span> <span style="color: #339933;">=</span> telefono<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase ConexionCliente.java</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">recursos</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.sql.DataSource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.jdbc.core.JdbcTemplate</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.jdbc.core.RowMapper</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">recursos.Cliente</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ClasesBean.Pedido</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConexionCliente  <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> DataSource conexion<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">List</span> listado<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Cliente cliente <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DataSource getConexion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> conexion<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setConexion<span style="color: #009900;">&#40;</span>DataSource conexion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span> <span style="color: #339933;">=</span> conexion<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Cliente buscarCliente<span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> telefono<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    	JdbcTemplate jdbctemplate <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JdbcTemplate<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #003399;">String</span> consulta <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select * from cliente where telefono = ?;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>telefono<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	    listado <span style="color: #339933;">=</span>  jdbctemplate.<span style="color: #006633;">query</span><span style="color: #009900;">&#40;</span>consulta,<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>telefono<span style="color: #009900;">&#125;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RowMapper</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
	    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> mapRow <span style="color: #009900;">&#40;</span><span style="color: #003399;">ResultSet</span> resultado, <span style="color: #000066; font-weight: bold;">int</span> filas<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span>  <span style="color: #003399;">SQLException</span>
    	<span style="color: #009900;">&#123;</span>
    		Cliente cliente <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Cliente<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	    cliente.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span>resultado.<span style="color: #006633;">getInt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    		cliente.<span style="color: #006633;">setNombre</span><span style="color: #009900;">&#40;</span>resultado.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	    cliente.<span style="color: #006633;">setTelefono</span><span style="color: #009900;">&#40;</span>resultado.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;telefono&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    	    <span style="color: #000000; font-weight: bold;">return</span>  cliente<span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
	    <span style="color: #009900;">&#125;</span>
	    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>listado.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	    <span style="color: #009900;">&#123;</span>
	    	  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;esta vacio&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span>
	    <span style="color: #000000; font-weight: bold;">else</span>
	    <span style="color: #009900;">&#123;</span>
	      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cliente</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Cliente<span style="color: #009900;">&#41;</span> listado.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cliente</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> insertarCliente <span style="color: #009900;">&#40;</span>Cliente cliente<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	JdbcTemplate jdbctemplate <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JdbcTemplate <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #003399;">String</span> consulta <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;insert into cliente (id,nombre,telefono) values (null,?,?);&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> objeto  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>  <span style="color: #009900;">&#123;</span>cliente.<span style="color: #006633;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,cliente.<span style="color: #006633;">getTelefono</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> 
&nbsp;
    	jdbctemplate.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>consulta, objeto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> insertarPedido <span style="color: #009900;">&#40;</span>Pedido pedido<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    	JdbcTemplate jdbctemplate <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JdbcTemplate <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #003399;">String</span> consulta <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;insert into pedidos (id,cliente_id,producto,unidades,gasto) values (null,?,?,?,?);&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
    	<span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> objeto <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>pedido.<span style="color: #006633;">getCliente</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,pedido.<span style="color: #006633;">getProducto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNombre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,pedido.<span style="color: #006633;">getProducto</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getUnidades</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,pedido.<span style="color: #006633;">getImporte</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    	jdbctemplate.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>consulta,objeto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> encontrarCliente <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> telefono<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
    	 JdbcTemplate jdbctemplate <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JdbcTemplate <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">conexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	 <span style="color: #003399;">String</span> consulta <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select id from cliente where telefono =&quot;</span><span style="color: #339933;">+</span>telefono<span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000066; font-weight: bold;">int</span> resultado <span style="color: #339933;">=</span>jdbctemplate.<span style="color: #006633;">queryForInt</span><span style="color: #009900;">&#40;</span>consulta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000000; font-weight: bold;">return</span> resultado<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Declaración de los bean en el fichero de configuración dispatcher-servlet.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.commons.dbcp.BasicDataSource&quot;</span> <span style="color: #000066;">destroy-method</span>=<span style="color: #ff0000;">&quot;close&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost:3306/libros_jdbc&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;clienteAplicacion&quot;</span></span>
&nbsp;
<span style="color: #009900;">    <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;actionflows.ClienteAplicacion&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;conexion&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;RegistroCliente&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;actionflows.RegistroCliente&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;conexion&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;GestionPedido&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;actionflows.GestionPedido&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;conexion&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Código de las jsp implicadas en el ejemplo</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span>
    pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">%&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags/form&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>formulario cliente<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span>formulario Aplicaci<span style="color: #339933;">&amp;</span>oacute<span style="color: #339933;">;</span>n Web flow<span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>form method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;aplicacion.html?&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_flowExecutionKey&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${flowExecutionKey}&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
&nbsp;
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Telefono<span style="color: #339933;">:&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;telefono&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_eventId_submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>formularionuevocliente.jsp formulario encargado de pedir los datos de nombre y de número de teléfono para insertar un nuevo cliente en la base de datos</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span>
    pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags/form&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Registro cliente<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
<span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>form method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;aplicacion.html&quot;</span> commandName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cliente&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_flowExecutionKey&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${flowExecutionKey}&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Introduce el nombre<span style="color: #339933;">:&lt;/</span>label<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
  <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Introduce el telefono<span style="color: #339933;">:&lt;/</span>label<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
  <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;telefono&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_eventId_submit&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&amp;</span>nbsp<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cancelar&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_eventId_cancel&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Código de formulariopedido.jsp, es la encargada de mostrar los datos de productos para ser seleccionados</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span>
    pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags/form&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;core&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>formulario pedidos aplicacion flow<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span> Formulario de pedido<span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>form method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;aplicacion.html&quot;</span> commandName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;producto&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Cliente <span style="color: #339933;">:</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span> $<span style="color: #009900;">&#123;</span>pedido.<span style="color: #006633;">cliente</span>.<span style="color: #006633;">nombre</span><span style="color: #009900;">&#125;</span> 
&nbsp;
 <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Lista de precios<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>table title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;lista de precios&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>Producto<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;</span>th<span style="color: #339933;">&gt;</span>Precio<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;&lt;/</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span>televisor<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">200</span> Euros<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;&lt;/</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span>telefono<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">120</span> Euros<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;&lt;/</span>tr<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span>frigorífico<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">450</span> Euros<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;&lt;/</span>tr<span style="color: #339933;">&gt;</span>
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span> Nombre producto<span style="color: #339933;">:&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>select path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;televisor&quot;</span> label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;televisor&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;telefono&quot;</span> label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;teléfono&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>option value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;frigorifico&quot;</span> label<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;frigorífico&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">:</span>select<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span> 
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span> Numero de unidades<span style="color: #339933;">:&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;unidades&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;3&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_flowExecutionKey&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${flowExecutionKey}&quot;</span><span style="color: #339933;">/&gt;</span>
 <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;_eventId_submit&quot;</span><span style="color: #339933;">&gt;&lt;/</span>input<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">raislymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/07/02/aplicacion-web-flow-jdbc-spring-framework-2%c2%ba-parte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ejemplo de aplicación para spring web flow</title>
		<link>http://www.railsymas.com/2011/04/19/ejemplo-de-aplicacion-para-spring-web-flow/</link>
		<comments>http://www.railsymas.com/2011/04/19/ejemplo-de-aplicacion-para-spring-web-flow/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 17:25:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2037</guid>
		<description><![CDATA[Habíamos visto en anteriores post el desarrollo de un un ejemplo de aplicación básica de spring web flow en el que se sentaban las bases sobre esta tecnología, (algo obsoleta desde un punto de vista tecnológico). En este ejemplo se profundiza un poco más además de aprovechar la conexión de base de datos de spring [...]]]></description>
			<content:encoded><![CDATA[<p>Habíamos visto en anteriores post el desarrollo de un un ejemplo de aplicación básica de spring web flow en el que se sentaban las bases sobre esta tecnología, (algo obsoleta desde un punto de vista tecnológico).</p>
<p>En este ejemplo se profundiza un poco más además de aprovechar la conexión de base de datos de spring mvc para integrarla en un ejemplo completo donde se muestran diferentes estados por donde transita la aplicación y establecemos una persistencia de los datos introducidos en los formularios.  </p>
<p><span id="more-2037"></span></p>
<p>Enlazando con el contenido puesto sobre web flow en anteriores post <a href="http://www.railsymas.com/2011/03/08/ejemplo-simple-de-web-flow-spring-framework/">ejemplo simple de web flow spring framework</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;flow</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/webflow&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/webflow</span>
<span style="color: #009900;">  http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;var</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pedido&quot;</span></span>
<span style="color: #009900;">   <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ClasesBean.Pedido&quot;</span></span>
<span style="color: #009900;">   <span style="color: #000066;">scope</span>=<span style="color: #ff0000;">&quot;flow&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;start-state</span> <span style="color: #000066;">idref</span>=<span style="color: #ff0000;">&quot;inicio&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-state</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;inicio&quot;</span></span>
&nbsp;
<span style="color: #009900;">  <span style="color: #000066;">view</span>=<span style="color: #ff0000;">&quot;formulariocliente&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;verificarcliente&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action-state</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;verificarcliente&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;clienteAplicacion&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;encontrado&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;pedido&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;vacio&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;nuevocliente&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action-state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-state</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;nuevocliente&quot;</span> <span style="color: #000066;">view</span>=<span style="color: #ff0000;">&quot;formularionuevocliente&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;render-actions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;clienteFormAction&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;setupForm&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/render-actions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;registrarcliente&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;clienteFormAction&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;bind&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;evaluate-action</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;flowScope.pedido.setCliente(requestScope.cliente)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/transition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action-state</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;registrarcliente&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;RegistroCliente&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;satisfactorio&quot;</span>  <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;pedido&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action-state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-state</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;pedido&quot;</span> <span style="color: #000066;">view</span>=<span style="color: #ff0000;">&quot;formulariopedido&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;render-actions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;productoFormAction&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;setupForm&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/render-actions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span>  <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;gestionarpedido&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;productoFormAction&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;bind&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;evaluate-action</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;flowScope.pedido.setProducto(requestScope.producto)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/evaluate-action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/transition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action-state</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;gestionarpedido&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;GestionPedido&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;satisfactorio&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;datospedido&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action-state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-state</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;datospedido&quot;</span> <span style="color: #000066;">view</span>=<span style="color: #ff0000;">&quot;datospedido&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transition</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;continue&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;fin&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-state<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;end-state</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;fin&quot;</span> <span style="color: #000066;">view</span>=<span style="color: #ff0000;">&quot;flowRedirect:aplicacion-flow&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>  
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/flow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/04/19/ejemplo-de-aplicacion-para-spring-web-flow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>spring mvc jdbc ejemplo</title>
		<link>http://www.railsymas.com/2011/04/14/spring-mvc-jdbc-ejemplo/</link>
		<comments>http://www.railsymas.com/2011/04/14/spring-mvc-jdbc-ejemplo/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 15:47:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2178</guid>
		<description><![CDATA[Evidentemente como todo lenguaje o framework el acceso a bases de datos es un factor fundamental para el desarrollo de un sitio web y como sistema de desarrollo spring no sería menos. Vemos en el siguiente ejemplo características propias del framework spring en el acceso mediante jdbc que permiten un tratamiento rápido de la información [...]]]></description>
			<content:encoded><![CDATA[<p>Evidentemente como todo lenguaje o framework el acceso a bases de datos es un factor fundamental para el desarrollo<br />
de un sitio web y como sistema de desarrollo spring no sería menos.</p>
<p><span id="more-2178"></span></p>
<p>Vemos en el siguiente ejemplo características propias del framework spring en el acceso mediante jdbc que permiten un tratamiento rápido de la información mediante una abstraccíon propia del framework que permite hacer las cosas un poco más rapido que otros frameworks como struts.</p>
<p>Una característica que en los nuevos framewroks rad (rapid application development) suponen una constante vital y que veremos cuando empecemos dichos desarrollos</p>
<p>Como todos los ejemplos estamos utlizando una base de datos común tanto j2ee jdbc, struts y jsf en spring utlizamos también la misma para facilitar el entendimiento.</p>
<p>Enlace al post jdbc j2ee  <a href="http://www.railsymas.com/2009/09/09/conexion-a-bases-de-datos-j2ee-jdbc/">conexion-a-bases-de-datos-j2ee-jdbc</a> </p>
<p>Clase bean asociada</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">ClasesBean</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DatosLibro <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> tematica<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> autor<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> titulo<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTematica<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> tematica<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTematica<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> tematica<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">tematica</span> <span style="color: #339933;">=</span> tematica<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getAutor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> autor<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setAutor<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> autor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">autor</span> <span style="color: #339933;">=</span> autor<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getTitulo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> titulo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTitulo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> titulo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">titulo</span> <span style="color: #339933;">=</span> titulo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Configuración dentro del fichero dispatcher-servlet.xml, declaramos la clase controladora e indicamos que tenemos un formulario llamado (formulariolibro) y mostramos los resultados mediante el formulario (resultadolibros) y la referencia al bean datasources  . Declaramos un bean datasource con el tipo de driver, el nombre de la base de datos y los valores del usuario para trabajar con la base de datos</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.commons.dbcp.BasicDataSource&quot;</span> <span style="color: #000066;">destroy-method</span>=<span style="color: #ff0000;">&quot;close&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverClassName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost:3306/libros_jdbc&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;/formulariolibros.html&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;controlador.ControladorJdbc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;formView&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;formulariolibros&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;successView&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;resultadolibros&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;datasource&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>controlador jdbc</p>
<p>En el ejemplo de código del controlador se pueden ver dos formas de trabajar en spring con jdbc, la primera es la forma habitual similar a la de j2ee o struts ( esta forma viene representada por el código del método conexionLibros, donde para poder insertar, eliminar y editar datos tenemos que malgastar tiempo en tediosas líneas de código para capturar las excepciones derivadas del tratamiento de datos con jdbc.</p>
<p>Los otros dos métodos se corresponden a una característica de spring que nos permite en el tratamiento de jdbc de una forma más rápida y cómoda. </p>
<p>Las plantillas jdbc de spring nos permiten limpiar el código y liberar el peso de la gestión de recursos y manejo de excepciones<br />
Nos permite por lo tanto escribir el código necesario para mover los datos. Spring nos permite abstraer el código estándar de jdbc, existen tres tipos de plantillas </p>
<p>JdbcTemplate nos crea la plantilla básica de acceso a jdbc y consultas sencillas indexadas<br />
NamedParameterJdbcTemplate nos crea la plantilla de acceso a jdbc, permite hacer consultas con valores unidos a parámetros nombrados en sql<br />
SimpleJdbcTemplate gestión de listas de parámetros variables simplificando la plantila jdbc</p>
<p>Para que jdbctemplate pueda funcionar necesitamos un datasource para conectar nuestra aplicación a la base de datos, se utiliza en los métodos  insertarJdbcTemplate y listadoJdbcTemplate</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">controlador</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.sql.DataSource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Connection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.PreparedStatement</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.ModelAndView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.mvc.SimpleFormController</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.jdbc.core.JdbcTemplate</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.jdbc.core.RowMapper</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ClasesBean.DatosLibro</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ControladorJdbc <span style="color: #000000; font-weight: bold;">extends</span> SimpleFormController <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> DataSource datasource<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">List</span> listado<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ControladorJdbc <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">setCommandClass</span><span style="color: #009900;">&#40;</span>DatosLibro.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">setCommandName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DatosLibro&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> insertarJdbcTemplate <span style="color: #009900;">&#40;</span>DatosLibro datoslibro <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		JdbcTemplate jdbctemplate <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JdbcTemplate<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">datasource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">String</span> consulta <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;insert into libros (id,titulo,autor,tematica) values (null,?,?,?);&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> objeto <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>datoslibro.<span style="color: #006633;">getTitulo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,datoslibro.<span style="color: #006633;">getAutor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,datoslibro.<span style="color: #006633;">getTematica</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		jdbctemplate.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span>consulta, objeto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">List</span> listadoJdbcTemplate <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">String</span> consulta <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select titulo , autor, tematica from libros;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	    JdbcTemplate jdbctemplate <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JdbcTemplate<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">datasource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    listado <span style="color: #339933;">=</span>  jdbctemplate.<span style="color: #006633;">query</span><span style="color: #009900;">&#40;</span>consulta, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RowMapper</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	    <span style="color: #009900;">&#123;</span>
	    	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> mapRow <span style="color: #009900;">&#40;</span><span style="color: #003399;">ResultSet</span> resultado, <span style="color: #000066; font-weight: bold;">int</span> filas<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span>  <span style="color: #003399;">SQLException</span>
	    	<span style="color: #009900;">&#123;</span>
	    		DatosLibro libro <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DatosLibro<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    	    libro.<span style="color: #006633;">setTitulo</span><span style="color: #009900;">&#40;</span>resultado.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	    libro.<span style="color: #006633;">setAutor</span><span style="color: #009900;">&#40;</span>resultado.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    	    libro.<span style="color: #006633;">setTematica</span><span style="color: #009900;">&#40;</span>resultado.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tematica&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    	    <span style="color: #000000; font-weight: bold;">return</span> libro<span style="color: #339933;">;</span>
	    	<span style="color: #009900;">&#125;</span>
	    <span style="color: #009900;">&#125;</span>
&nbsp;
	    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #000000; font-weight: bold;">return</span> listado<span style="color: #339933;">;</span>		
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> conexionLibros <span style="color: #009900;">&#40;</span>DatosLibro datoslibro<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Connection</span> conexion <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> consulta <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;insert into libros (id,titulo,autor,tematica) values (?,?,?,?);&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">PreparedStatement</span> preparedstatement <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
			conexion <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">datasource</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			 preparedstatement <span style="color: #339933;">=</span> conexion.<span style="color: #006633;">prepareStatement</span><span style="color: #009900;">&#40;</span>consulta<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			preparedstatement.<span style="color: #006633;">setInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			preparedstatement.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>,datoslibro.<span style="color: #006633;">getTitulo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			preparedstatement.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, datoslibro.<span style="color: #006633;">getAutor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			preparedstatement.<span style="color: #006633;">setString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span>, datoslibro.<span style="color: #006633;">getTematica</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			preparedstatement.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;conexion&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">finally</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span>
			<span style="color: #009900;">&#123;</span>
			conexion.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			preparedstatement.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ModelAndView onSubmit <span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> command<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>   
&nbsp;
		DatosLibro datoslibro <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DatosLibro<span style="color: #009900;">&#41;</span> command<span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//this.conexionLibros(datoslibro);</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">insertarJdbcTemplate</span><span style="color: #009900;">&#40;</span>datoslibro<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">List</span> listado <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">listadoJdbcTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;resultadolibros&quot;</span>,<span style="color: #0000ff;">&quot;listado&quot;</span>,listado<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDatasource<span style="color: #009900;">&#40;</span>DataSource datasource<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">datasource</span> <span style="color: #339933;">=</span> datasource<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Se introducen los datos 6 de título, autor y temática</p>
<p>código de las páginas jsp </p>
<p>Formulariolibros.jsp primera imagen</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=ISO-8859-1&quot;</span>  pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ISO-8859-1&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags/form&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;form&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=ISO-8859-1&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libros.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libros.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>h2<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>form method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> commandName<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;DatosLibro&quot;</span><span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libro.titulo&quot;</span><span style="color: #339933;">/&gt;</span>
     <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
     <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libro.autor&quot;</span><span style="color: #339933;">/&gt;</span>
     <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
     <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;autor&quot;</span><span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libro.tematica&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>form<span style="color: #339933;">:</span>input path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tematica&quot;</span><span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span><span style="color: #339933;">/&gt;</span> 
&nbsp;
   <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Resultadolibros.jsp sengunda imagen</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=ISO-8859-1&quot;</span>     pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ISO-8859-1&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=ISO-8859-1&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estilo.css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;resultadojdbc.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;&lt;</span>spring<span style="color: #339933;">:</span>message code<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;resultadojdbc.titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>h2<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tabla&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>table title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;listado de libros&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>titulo<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>autor<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>th<span style="color: #339933;">&gt;</span>tematica<span style="color: #339933;">&lt;/</span>th<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">forEach</span> items<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${listado}&quot;</span> var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libro&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${libro.titulo}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;par&quot;</span><span style="color: #339933;">&gt;&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${libro.autor}&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span> 
     <span style="color: #339933;">&lt;</span>td <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;impar&quot;</span><span style="color: #339933;">&gt;&lt;</span>c<span style="color: #339933;">:</span>out value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${libro.tematica}&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>c<span style="color: #339933;">:</span>forEach<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span> www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span> <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>


<a href='http://www.railsymas.com/2011/04/14/spring-mvc-jdbc-ejemplo/sprinjdbc1/' title='sprinjdbc1'><img width="150" height="150" src="http://www.railsymas.com/wp-content/uploads/2011/04/sprinjdbc1-150x150.png" class="attachment-thumbnail" alt="sprinjdbc1" title="sprinjdbc1" /></a>
<a href='http://www.railsymas.com/2011/04/14/spring-mvc-jdbc-ejemplo/springjdbc2/' title='springjdbc2'><img width="150" height="150" src="http://www.railsymas.com/wp-content/uploads/2011/04/springjdbc2-150x150.png" class="attachment-thumbnail" alt="springjdbc2" title="springjdbc2" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/04/14/spring-mvc-jdbc-ejemplo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ejemplo de spring mvc tiles 2.0</title>
		<link>http://www.railsymas.com/2011/04/09/ejemplo-de-spring-mvc-tiles-2-0/</link>
		<comments>http://www.railsymas.com/2011/04/09/ejemplo-de-spring-mvc-tiles-2-0/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 22:21:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2154</guid>
		<description><![CDATA[Spring mvc al igual que struts permite el uso y creación de plantillas para la creación de layouts Como toda plantilla la finalidad principal es la de tener un esquema visual similar en todas las distintas secciones del sitio web, este tipo de esquema visuales suele ser rentable en sitios con unas cuantas secciones ya [...]]]></description>
			<content:encoded><![CDATA[<p>Spring mvc al igual que struts permite el uso y creación de plantillas para la creación de layouts </p>
<p><span id="more-2154"></span></p>
<p>Como toda plantilla la finalidad principal es la de tener un esquema visual similar en todas las distintas secciones del sitio web, este tipo de esquema visuales suele ser rentable en sitios con unas cuantas secciones ya que el tiempo de desarrollo se recorta bastante.</p>
<p>Hoy en día con la entrada de los cms y framework de última generación todos con independencia del leguaje con el que se desarrollan suelen tener un buen soporte para plantillas posibilitado y abaratando los costes a la hora de renovar o desarrollar un nuevo site.</p>
<p>Por lo tanto frameworks obsoletos como struts, spring y jsf  dentro de la aplicaciones j2ee permiten el desarrollo de layouts pero de una forma más costosa en el código.</p>

<a href='http://www.railsymas.com/2011/04/09/ejemplo-de-spring-mvc-tiles-2-0/sprintile1/' title='sprintile1'><img width="150" height="150" src="http://www.railsymas.com/wp-content/uploads/2011/04/sprintile1-150x150.png" class="attachment-thumbnail" alt="sprintile1" title="sprintile1" /></a>
<a href='http://www.railsymas.com/2011/04/09/ejemplo-de-spring-mvc-tiles-2-0/springtile2/' title='springtile2'><img width="150" height="150" src="http://www.railsymas.com/wp-content/uploads/2011/04/springtile2-150x150.png" class="attachment-thumbnail" alt="springtile2" title="springtile2" /></a>
<a href='http://www.railsymas.com/2011/04/09/ejemplo-de-spring-mvc-tiles-2-0/sprinttiles3/' title='sprinttiles3'><img width="150" height="150" src="http://www.railsymas.com/wp-content/uploads/2011/04/sprinttiles3-150x150.png" class="attachment-thumbnail" alt="sprinttiles3" title="sprinttiles3" /></a>
<a href='http://www.railsymas.com/2011/04/09/ejemplo-de-spring-mvc-tiles-2-0/estructuratiles/' title='estructuratiles'><img width="150" height="150" src="http://www.railsymas.com/wp-content/uploads/2011/04/estructuratiles-150x150.png" class="attachment-thumbnail" alt="estructuratiles" title="estructuratiles" /></a>

<p>La css es la misma que para el caso de struts tiles para la categoría de struts, tenemos un esqueleto general de la plantilla<br />
es un fichero denominado plantilla.jsp con el siguiente código, tenemos cuatro bloques cabecera, menú, cuerpo y pie donde insertamos cada uno de los fragmentos que luego son cubiertos las páginas correspondientes. </p>
<p>En esencia es exacmente igual que en struts y muchos de los conceptos sirven para spring<br />
<a href="http://www.railsymas.com/2009/10/25/struts-tiles-proyecto-web-eclipse/">struts-tiles</a></p>
<p>Código de plantilla.jsp</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=ISO-8859-1&quot;</span>  pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ISO-8859-1&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://tiles.apache.org/tags-tiles&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tiles&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=ISO-8859-1&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;css/estiloplantilla.css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>tiles<span style="color: #339933;">:</span>getAsString name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cabecera&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>tiles<span style="color: #339933;">:</span>insertAttribute name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cabecera&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenido&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;menu&quot;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span>tiles<span style="color: #339933;">:</span>insertAttribute name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;menu&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cuerpo&quot;</span><span style="color: #339933;">&gt;</span>
       <span style="color: #339933;">&lt;</span>tiles<span style="color: #339933;">:</span>insertAttribute name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cuerpo&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>tiles<span style="color: #339933;">:</span>insertAttribute name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Necesitamos entonces el código de las otras tres páginas que correponden a los bloques de pie, menu y cuerpo así como las páginas correspondientes a los objetos y los personajes</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2011/04/estructuratiles.png" alt="" title="estructuratiles" width="238" height="208" class="alignnone size-full wp-image-2169" /></p>
<p>cabecera.jsp</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://tiles.apache.org/tags-tiles&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tiles&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;imagencabecera&quot;</span><span style="color: #339933;">&gt;</span>    	
       <span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code='imagen.cabecera'/&gt;&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code='imagen.cabecera.alt'/&gt;&quot;</span><span style="color: #339933;">/&gt;</span>     
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>menu.jsp</p>
<p>Nos permite seleccionar los enlaces correspondientes para acceder a la sección de objetos y personajes</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/jsp/jstl/core&quot;</span>  prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;</span>ul id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;menu_lateral&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;c:url value=&quot;</span><span style="color: #339933;">/</span>objetos.<span style="color: #006633;">html</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">&gt;</span> objetos<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;c:url value=&quot;</span><span style="color: #339933;">/</span>personajes.<span style="color: #006633;">html</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">&gt;</span> personajes<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>cuerpo de la aplicación será el bloque que cambiará de la vista de inicio a la vista de objetos y personajes</p>
<p>cuerpo.jsp</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
 <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>
   Ejemplo de desarrollo con spring<span style="color: #339933;">-</span>tiles <span style="color: #cc66cc;">2.0</span>, tenemos una plantilla base y diferentes definiciones de 
   p<span style="color: #339933;">&amp;</span>aacute<span style="color: #339933;">;</span>gina en un fichero xml llamado tiles<span style="color: #339933;">-</span>def.<span style="color: #006633;">xml</span>
  <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenido&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">lapices</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">lapices</span>.<span style="color: #006633;">alt</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">/&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>pie de la aplicación pie.jsp</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>p id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pizquierda&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>a  href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ejercicios.html&quot;</span><span style="color: #339933;">&gt;</span>Ejercicios <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;|&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;plantilla.html&quot;</span><span style="color: #339933;">&gt;</span> Plantilla <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;|</span> <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;objetos.html&quot;</span><span style="color: #339933;">&gt;</span> Objetos<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span> <span style="color: #339933;">|&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;personajes.html&quot;</span><span style="color: #339933;">&gt;</span> Personajes <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>p id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pderecha&quot;</span><span style="color: #339933;">&gt;</span> @CopyRight railsymas.<span style="color: #006633;">com</span> <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>una vez tenemos el esquema básico las vistas pueden variar en función de las acciones de los usuarios al seleccionar la vista de objetos o de personajes y desde cualquiera de ellas volver a la de plantilla</p>
<p>Código de la página personajes, simplemente estamos modificando un bloque de la plantilla el correspondiente al cuerpo</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
&nbsp;
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;imagenes&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">personaje1</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">personaje1</span>.<span style="color: #006633;">alt</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">/&gt;</span>
 <span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">personaje2</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">personaje2</span>.<span style="color: #006633;">alt</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">/&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Código de la página personajes, simplemente estamos modificando un bloque de la plantilla el correspondiente al cuerpo</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.springframework.org/tags&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spring&quot;</span> <span style="color: #339933;">%&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;imagenes&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">objeto1</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">objeto1</span>.<span style="color: #006633;">alt</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">/&gt;</span>
 <span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">objeto2</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;spring:message code=&quot;</span>imagen.<span style="color: #006633;">objeto2</span>.<span style="color: #006633;">alt</span><span style="color: #0000ff;">&quot;/&gt;&quot;</span><span style="color: #339933;">/&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Necesitamos crear un fichero de configuracion tiles-def.xml donde declaramos la estructura de las plantillas. Siguiendo el ejemplo de struts tiles las explicaciones son las mismas como resumen se crea un esqueleto base llamado plantilla del cual extienden objetos y personajes sobreescribiendo el cuerpo (al igual que la herencia de objetos)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE tiles-definitions PUBLIC</span>
<span style="color: #00bbdd;">       &quot;-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN&quot;</span>
<span style="color: #00bbdd;">       &quot;http://tiles.apache.org/dtds/tiles-config_2_0.dtd&quot;&gt;</span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tiles-definitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;${YOUR_DEFINITION_HERE}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;plantilla&quot;</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;WEB-INF/pages/tiles/plantilla.jsp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Plantillas Spring&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cabecera&quot;</span>  <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/tiles/cabecera.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;menu&quot;</span>  <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/tiles/menu.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cuerpo&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/tiles/cuerpo.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pie&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/tiles/pie.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;objetos&quot;</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">&quot;plantilla&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Plantilla Spring Objetos&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cuerpo&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/tiles/objetos.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;personajes&quot;</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">&quot;plantilla&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Plantilla Spring Personajes&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cuerpo&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/tiles/personajes.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tiles-definitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Dentro del archivo de configuración de spring en según el ejemplo dispatcher-sevlet,xml.</p>
<p>Para integrar tiles en spring mvc hay que decirle a tiles que abra el archivo de configuración de tiles para poner a disposición de la vistas al declarar una instacia TilesConfigurer. Tenemos una propiedad definitions donde se declara la lista de archivos de definición.(tiles-def.xml)</p>
<p>Por último es necesario configurar un resolutor de vista específico para tiles para que el usuario una vez elegida una pantalla pueda ver el resultado. Cambiamos InternalViewResolver por  ResourceBundleViewResolver, con internal resolvían las vistas formadas por y prefijo nombre de vista y sufijo pero con Resource las url de las vistas se resuelven en un archivo de propiedades otra más que nos ofrece spring</p>
<p>para ello se crean las clases correspondientes a las vistas de los beans desde el archivo indicado por el valor basename<br />
en este caso views por lo que entonces tenemos un fichero de propiedades views.properties si el valor fuese vistas entonces sería vistas.properties</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">personajes.(class) = org.springframework.web.servlet.view.tiles2.TilesView
personajes.url = personajes
&nbsp;
objetos.(class) = org.springframework.web.servlet.view.tiles2.TilesView
objetos.url = objetos
&nbsp;
plantilla.(class) = org.springframework.web.servlet.view.tiles2.TilesView
plantilla.url = plantilla
&nbsp;
ejercicios.(class) = org.springframework.web.servlet.view.JstlView
ejercicios.url=/WEB-INF/pages/ejercicios.jsp</pre></td></tr></table></div>

<p>Y dentro del package Plantillas y para personas otra clase igual y para objetos otra clase igual</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">Plantillas</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.stereotype.Controller</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.RequestMapping</span><span style="color: #339933;">;</span>
&nbsp;
@Controller
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Plantilla <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
&nbsp;
		@RequestMapping<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/plantilla.html&quot;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> redirect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;plantilla&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
&nbsp;
  <span style="color: #339933;">&lt;</span>context<span style="color: #339933;">:</span>component<span style="color: #339933;">-</span>scan base<span style="color: #339933;">-</span><span style="color: #000000; font-weight: bold;">package</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Plantillas&quot;</span> <span style="color: #339933;">/&gt;</span>   
&nbsp;
    <span style="color: #339933;">&lt;</span>bean id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;viewTilesResolver&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;org.springframework.web.servlet.view.ResourceBundleViewResolver&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;basename&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;views&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>bean<span style="color: #339933;">&gt;</span>    
    <span style="color: #339933;">&lt;</span>bean id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tilesConfigurer&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;org.springframework.web.servlet.view.tiles2.TilesConfigurer&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;definitions&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>list<span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span>value<span style="color: #339933;">&gt;/</span>WEB<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>tiles<span style="color: #339933;">-</span>def.<span style="color: #006633;">xml</span><span style="color: #339933;">&lt;/</span>value<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>list<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>property<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>bean<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>ejemplo de tiles dinamicas <a href="http://www.springbyexample.org/examples/dynamic-tiles-spring-mvc-module.html">dynamic-tiles-spring-mvc-module.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/04/09/ejemplo-de-spring-mvc-tiles-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

