【发布时间】:2017-09-13 09:02:22
【问题描述】:
所以我有模型实体Place,它必须初始化一些关系。
现在我在控制器中使用自动创建的模型表单支持 bean,如下所示:
@GetMapping(value = "/add")
public String addPlacePage(final Place place, Model model) {
model.addAttribute("services", serviceRepository.findAll())
.addAttribute("categories", categoryRepository.findAll())
.addAttribute("cities", cityRepository.findAll());
return "admin/place/addPlace";
}
Place place 是我的 Spring 创建的(可能是 Spring-MVC)。有没有办法为支持bean提供工厂方法?我不想在控制器中这样做。
我曾尝试将工厂代码放入我的配置中,如下所示:
@Bean
@Scope(value = "prototype")
public Place place() {
log.info("Creating place in FACTORY");
Place place = EntityFactory.emptyPlace();
return place;
}
但这不起作用。
【问题讨论】:
标签: javascript spring spring-mvc spring-boot