Last active
December 29, 2015 03:38
-
-
Save alexandreaquiles/fe0746a1890a3baf96ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>Listagem com Ajax</title> | |
| <script type="text/javascript" src="resources/js/jquery.js"></script> | |
| </head> | |
| <body> | |
| <script type="text/javascript"> | |
| function listaTarefas(){ | |
| $.get('tarefa/listaAjax', null, function(tarefas) { | |
| for(var i = 0 ; i < tarefas.length; i ++){ | |
| var tarefa = tarefas[i]; | |
| var tr = '<tr>'+ | |
| '<td>'+tarefa.id+'</td>'+ | |
| '<td>'+tarefa.descricao+'</td>'+ | |
| '<td>'+tarefa.finalizado+'</td>'+ | |
| '<td>'+new Date(tarefa.dataFinalizacao)+'</td>'+ | |
| '<td><a href="#" onclick="carregaTarefa('+tarefa.id+')">Carrega</a></td>'+ | |
| '</tr>'; | |
| $('#tabela_tarefas').append(tr); | |
| } | |
| }, "json"); | |
| } | |
| function carregaTarefa(id){ | |
| $.get('tarefa/'+id, null, function(tarefa) { | |
| var detalhe = '<p><strong>Id:</strong>'+tarefa.id+'<br/>'+ | |
| '<strong>Descrição:</strong>'+tarefa.descricao+'<br/>'+ | |
| '<strong>Finalizado:</strong>'+tarefa.finalizado+'<br/>'+ | |
| '<strong>Data Finalização:</strong>'+new Date(tarefa.dataFinalizacao)+'<br/>'+ | |
| '<a href="#" onclick="carregaTarefa('+tarefa.id+'">Carrega</a></p>'; | |
| $('#detalhe_tarefa').html(detalhe); | |
| }, "json"); | |
| } | |
| </script> | |
| <h1>Caelum Spring MVC - página principal</h1> | |
| <hr/> | |
| <h2>Tarefas</h2> | |
| <a href="tarefa/lista">Lista de Tarefas</a> | |
| <a href="#" onclick="listaTarefas()">Lista de Tarefas AJAX</a> | |
| <hr/> | |
| <div id="detalhe_tarefa"></div> | |
| <hr/> | |
| <table id="tabela_tarefas"></table> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.3.0/jackson-databind-2.3.0.jar | |
| http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.3.0/jackson-annotations-2.3.0.jar | |
| http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.3.0/jackson-core-2.3.0.jar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>br.com.caelum</groupId> | |
| <artifactId>agenda</artifactId> | |
| <packaging>war</packaging> | |
| <version>1.0-SNAPSHOT</version> | |
| <name>agenda Maven Webapp</name> | |
| <url>http://maven.apache.org</url> | |
| <properties> | |
| <spring.version>3.2.4.RELEASE</spring.version> | |
| <jdk.version>1.7</jdk.version> | |
| </properties> | |
| <dependencies> | |
| <dependency> | |
| <groupId>org.springframework</groupId> | |
| <artifactId>spring-webmvc</artifactId> | |
| <version>${spring.version}</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>mysql</groupId> | |
| <artifactId>mysql-connector-java</artifactId> | |
| <version>5.1.26</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>org.hibernate</groupId> | |
| <artifactId>hibernate-validator</artifactId> | |
| <version>5.0.1.Final</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>javax.servlet</groupId> | |
| <artifactId>jstl</artifactId> | |
| <version>1.2</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>taglibs</groupId> | |
| <artifactId>standard</artifactId> | |
| <version>1.1.2</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>javax.servlet</groupId> | |
| <artifactId>javax.servlet-api</artifactId> | |
| <version>3.0.1</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>com.fasterxml.jackson.core</groupId> | |
| <artifactId>jackson-databind</artifactId> | |
| <version>2.3.0</version> | |
| </dependency> | |
| </dependencies> | |
| <build> | |
| <finalName>agenda</finalName> | |
| <plugins> | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-compiler-plugin</artifactId> | |
| <version>3.0</version> | |
| <configuration> | |
| <source>${jdk.version}</source> | |
| <target>${jdk.version}</target> | |
| </configuration> | |
| </plugin> | |
| </plugins> | |
| </build> | |
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Controller | |
| class TarefasController { | |
| //restante omitido - mas não remova! | |
| @RequestMapping("tarefa/listaAjax") | |
| public @ResponseBody List<Tarefa> listaAjax() { | |
| JdbcTarefaDao dao = new JdbcTarefaDao(); | |
| return dao.lista(); | |
| } | |
| @RequestMapping("tarefa/{id}") | |
| public @ResponseBody Tarefa porId(@PathVariable Long id) { | |
| JdbcTarefaDao dao = new JdbcTarefaDao(); | |
| return dao.buscaPorId(id); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment