Mybitis+springMVC 套路
springMVC:确保能够扫描到所有注解
<!-- 使用Annotation自动注册Bean,只扫描@Controller --> <context:component-scan base-package="com.jeeplus" use-default-filters="false"><!-- base-package 如果多个,用“,”分隔 --> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
Controller:标注@Controller 并在service标注@Autowired
@Controller public class ApplyRegisterController extends BaseController{ private static final long serialVersionUID = 1L; @Autowired private DepositService<Depositer> depositService;
}
Service:标注@Service @Transactional 并在方法上标注@Override
@Service @Transactional public class DepositService<T> extends CrudService<DepositDao,Depositer> { @Override public Depositer get(String id) { return super.get(id); }
Dao:标注@MyBatisDao
@MyBatisDao public interface DepositDao extends CrudDao<Depositer>{ }
Mapper: 设置dao层路径
<mapper namespace="com.jeeplus.modules.loan.dao.DepositDao"></mapper>
总结:
注解路线 :@Controller------>@Service-------->@MyBatisDao
报错:
1、检查注解是否引用错误(一般是启动报错或者运行时报空指针);
2、Service层一般需要标注@Transactional 开启事务(一般是运行报错);