Skip to content

Instantly share code, notes, and snippets.

@mcaserta
Created March 6, 2012 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcaserta/1988943 to your computer and use it in GitHub Desktop.
Save mcaserta/1988943 to your computer and use it in GitHub Desktop.
File usati per il video "Introduzione a Spring Roo"
// il video che spiega questo script si trova all'indirizzo:
// https://vimeo.com/38038686
project --topLevelPackage com.nexse.swat.pizza
jpa setup --database H2_IN_MEMORY --provider HIBERNATE
entity jpa --class ~.domain.Base --testAutomatically
field string --fieldName name --sizeMin 2 --notNull
entity jpa --class ~.domain.Topping --testAutomatically
field string --fieldName name --sizeMin 2 --notNull
entity jpa --class ~.domain.Pizza --testAutomatically
field string --fieldName name --sizeMin 2 --notNull
field number --fieldName price --type java.math.BigDecimal
field set --fieldName toppings --type ~.domain.Topping
field reference --fieldName base --type ~.domain.Base
web mvc setup
web mvc all --package ~.web
focus --class ~.domain.Topping
field set --fieldName pizzas --type ~.domain.Pizza --cardinality MANY_TO_MANY --mappedBy toppings
package com.nexse.swat.pizza.web;
import com.nexse.swat.pizza.domain.Pizza;
import com.nexse.swat.pizza.domain.Topping;
import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
@RequestMapping("/toppings")
@Controller
@RooWebScaffold(path = "toppings", formBackingObject = Topping.class)
public class ToppingController {
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@Valid Topping topping, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
populateEditForm(uiModel, topping);
return "toppings/create";
}
uiModel.asMap().clear();
topping.persist();
for (Pizza pizza : topping.getPizzas()) {
Pizza p = Pizza.findPizza(pizza.getId());
p.getToppings().add(topping);
p.merge();
}
return "redirect:/toppings/" + encodeUrlPathSegment(topping.getId().toString(), httpServletRequest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment