Last active
May 1, 2017 03:15
-
-
Save BrunoDSouza/0f19851d5efc9cd084e663befe572071 to your computer and use it in GitHub Desktop.
Codigo para passar dados em JSON, converte-los para o objeto em questão, apos isso redirecionar para outra View
This file contains 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 | |
@RequestMapping("/movimentacao") | |
public class ItemController { | |
@PostMapping("/novo") | |
public @ResponseBody ModelAndView listar(@RequestBody String items) throws JsonParseException, JsonMappingException, IOException{ | |
ObjectMapper mapper = new ObjectMapper(); | |
List<ItemsMovimentacao> listItens = mapper.readValue(items, TypeFactory.defaultInstance() | |
.constructCollectionType(List.class, ItemsMovimentacao.class)); | |
ModelAndView mv = new ModelAndView("produto/pesquisa-produto"); | |
mv.addObject("items",listItens); | |
return mv; | |
} | |
} |
This file contains 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
var item = { | |
request : function(listItem){ | |
var dados = JSON.stringify(listItem); | |
$.ajax({ | |
type : "POST", | |
contentType : "application/json", | |
url : "/movimentacao/novo", | |
data : dados, | |
success : function(data){ | |
alert("Deu certo!"); | |
}, | |
error : function(e) { | |
alert("ERROR: " + e.responseText) | |
} | |
}) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment