@Controller("adminAdController")
@RequestMapping("/console/ad")
public class AdController extends BaseController
{
/**
* 保存第一步
*/
@RequestMapping(value = "/save1", method = RequestMethod.POST)
public String save1(Ad ad, Long adCategoryId,ModelMap model, RedirectAttributes redirectAttributes)
{
AdCategory adCategory = adCategoryService.find(adCategoryId);
ad.setAdCategory(adCategory);
if (ad.getType() == Type.app)
{
ad.setAdSite(null);
}
else
{
ad.setPlatform(null);
ad.setAdPackageUrl(null);
ad.setAppName(null);
ad.setAppAuthor(null);
ad.setAppDescription(null);
}
adService.save(ad);
model.addAttribute("menuId", Ad.class.getSimpleName());
model.addAttribute("success", "广告基本信息已添加,请添加定向内容");
Long id = ad.getId();
return "redirect:add2.ct?success=true&id="+id;
}
/**
* 添加第2步
*/
@RequestMapping(value = "/add2", method = RequestMethod.GET)
public String add2(ModelMap model,Boolean success, Long id, RedirectAttributes redirectAttributes)
{
List dictSchools = dictSchoolService.findAll();
model.addAttribute("dictSchools", dictSchools);
if( success != null){
}else{
addFlashMessage(redirectAttributes, new Message(com.sammyun.Message.Type.error, "请先成功添加广告"));
return "redirect:list.ct";
}
model.addAttribute("success", "广告基本信息已添加,请添加定向内容");
model.addAttribute("id", id);
model.addAttribute("menuId", Ad.class.getSimpleName());
return "/console/ad/add2";
}
}
不同Controller的跳转
方式一:使用ModelAndView
return new ModelAndView("redirect:/toList"); 这样可以重定向到toList这个方法
方式二:返回String
return "redirect:/ toList ";
Controller的跳转 带参数
方式一:自己手动拼接url
new ModelAndView("redirect:/toList?param1="+value1+"¶m2="+value2); 这样有个弊端,就是传中文可能会有乱码问题。
方式二:用RedirectAttributes
这个是发现的一个比较好用的一个类,这里用它的addAttribute方法,这个实际上重定向过去以后你看url,是它自动给你拼了你的url。
attr.addAttribute("param", value);
return "redirect:/namespace/toController";
这样在toController这个方法中就可以通过获得参数的方式获得这个参数,再传递到页面。过去的url还是和方式一样的。
方式三:返回string拼接参数
return "redirect:add2.ct?success=true&id="+id;
参考:http://www.cnblogs.com/youngjoy/p/3919656.html