Controller注意事項(xiàng)
controller中使用屬性的bug
由于controller是單例的,所以使用屬性會(huì)造成邏輯混亂
解決方法為加@Scope("prototype")注解,讓它成為非單例模式
查看源碼Scope注解并沒(méi)有@Inherited注解,所以不能考慮繼承了,只能每個(gè)controller都加注解
如果是新項(xiàng)目,大可根據(jù)spring約定規(guī)范,使用單例controller,不用屬性
如果是老項(xiàng)目,不想改動(dòng)太多代碼,就在controller加上@Scope("prototype")