Skip to content

Instantly share code, notes, and snippets.

@franz-ka
Created July 28, 2011 14:17
Show Gist options
  • Save franz-ka/1111623 to your computer and use it in GitHub Desktop.
Save franz-ka/1111623 to your computer and use it in GitHub Desktop.
First GAE + Spring MVC : Controllers
package com.gae.app;
// ... imports ...
@Controller
public class Controller1 {
@RequestMapping("/", method = RequestMethod.GET, params="miParam=miValor")) //solo si miParam esta
public void hello(@RequestParam("miValor") String unValor) {}
@RequestMapping("/articulos", method = RequestMethod.POST, headers="content-type=text/*")
@RequestMapping("/{usuario}")
@ResponseBody //devuelve HTML puro
public String getUsuario(@PathVariable String usuario, Model model) {}
}
@Controller
@RequestMapping("/articulos")
public class Controller2 {
@RequestMapping(value="/{id}") //mapea ../articulos/5, ../articulos/45, etc.
public void getArticulo(@PathVariable Long id, Model model) {}
@RequestMapping(value="/proovedores/{provId}/franquisias/{franId}")
public void getFranquisia(@PathVariable long provId, @PathVariable long franId, Model model) {}
}
@Controller
@RequestMapping("/personas/{persona}")
public class Controller3 {
@RequestMapping(value = "/mascotas/{mascotaId}"
public void getMascota(@PathVariable String persona, @PathVariable long mascotaId, Model model) {}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.gae.app"/>
// ...
</beans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment