在spring框架中,我想将一些变量(对象)传递给jsp页面。我可以传递一个对象:
ModelAndView modelAndView= new ModelAndView("JspPageName", "message", message);
return message
但是我怎样才能将多个对象从 java 发送到 jsp。实际上我知道我可以创建一个对象数组并发送这个数组,但是我想知道这样做的最佳方法我将数据发送到 jsp 的代码是这样的:
@Controller
public class DomainEkleController {
private DomainJDBCTemplate domainJDBCTemplate;
private MemurJDBCTemplate memurJDBCTemplate;
@ModelAttribute("Domain")
public Domain getDomain()
{
return new Domain();
}
@Autowired
@Qualifier("domainJDBCTemplate")
public void setDomainJDBCTemplate(DomainJDBCTemplate domainJDBCTemplate) {
this.domainJDBCTemplate = domainJDBCTemplate;
}
@Autowired
@Qualifier("memurJDBCTemplate")
public void setMemurJDBCTemplate(MemurJDBCTemplate memurJDBCTemplate) {
this.memurJDBCTemplate = memurJDBCTemplate;
}
@RequestMapping(value="/DomainEkle")
public ModelAndView domainEkle() {
List<Memur> memurlar=memurJDBCTemplate.getAll();
System.out.println(memurlar);
/*for(Memur x:memurlar)
{
System.out.println(x.getIsim());
}*/
String message = "Hello World, Spring 3.0!";
ModelAndView domain_ekle= new ModelAndView("DomainEkle", "message", message);
return domain_ekle;
}
@RequestMapping(value="/DomainEkle",method=RequestMethod.POST)
public ModelAndView domain_eklendi_fonksiyon(@ModelAttribute("Domain")Domain domain, ModelMap model)
{
model.addAttribute("domain_adi", domain.getDomain_adi());
model.addAttribute("sunucu_no", domain.getSunucu_no());
model.addAttribute("tarih", domain.getTarih());
model.addAttribute("ilgili_memur_no",domain.getIlgili_memur_no());
String message="Domain Kaydi Yapilmistir!";
ModelAndView dm_eklendi=new ModelAndView("DomainEkle","message",message);
domainJDBCTemplate.addDomain(domain);
return dm_eklendi;
}
}