Не могли бы вы просто использовать Модель и передавать свои переменные таким образом? Вот пример кода, который я использую.
@Controller
@Scope("prototype")
@RequestMapping("/favorites")
public class FavoritesController {
protected final Log logger = LogFactory.getLog(getClass());
@Autowired
FavoriteService favoriteService;
@RequestMapping(method = RequestMethod.POST)
public void handle(String circuit, String customer, String action, Model model) {
String userid = SecurityContextHolder.getContext().getAuthentication().getName();
List<Map<String, String>> favorites = null;
if (action.equals("save")) {
favoriteService.setFavorite(userid, circuit, customer);
favorites = favoriteService.getFavorites(userid);
}
if (action.equals("delete")) {
favoriteService.deleteFavorite(userid, circuit);
favorites = favoriteService.getFavorites(userid);
}
model.addAttribute("userid", userid);
model.addAttribute("circuit", circuit);
model.addAttribute("customer", customer);
model.addAttribute("favorites", favorites);
}
}
[Отредактировано, чтобы добавить часть jquery этого]
// ****************************************
// SAVE TO FAVORITES
// ****************************************
$("#save-to-favorite").live("click", function() {
var saveCircuit = $(this).attr('circuit');
var saveCustomer = $(this).attr('customer');
var data = "action=save&circuit=" + saveCircuit + "&customer=" + saveCustomer;
$.ajax( {
type : "POST",
url : "favorites.html",
data : data,
success : function(xhr) {
$("#favorite-list").html(xhr);
},
error : function(xhr) {
var response = xhr.responseText;
response = response.replace(/<html>.+<body>/i, "")
response = response.replace(/<\/body><\/html>/i, "")
alert(response);
}
});
});
// ****************************************
// DELETE FROM FAVORITES
// ****************************************
$(".delete-favorite-icon").live("click", function() {
var deleteCircuit = $(this).attr('circuit');
var data = "action=delete&circuit=" + deleteCircuit;
$.ajax( {
type : "POST",
url : "favorites.html",
data : data,
success : function(xhr) {
$("#favorite-list").html(xhr);
},
error : function(xhr) {
var response = xhr.responseText;
response = response.replace(/<html>.+<body>/i, "")
response = response.replace(/<\/body><\/html>/i, "")
alert(response);
}
});
});
`