//查询当前用户uid,通过uid查询出用户的收货地址
User user = (User) session.getAttribute("user");
IAddressService addressService = new AddressService();
List<Address> addrByUid = addressService.findAddrByUid(user.getUid());
model.addAttribute("cartItemByPid",cartItemByPid);
model.addAttribute("addrByUid",addrByUid);
model.addAttribute("sum",sum);
return "orderSubmit";
起初也是觉得可能addressService 层只需要调用一次,所以就没有在成员变量中用注解注入,自己创建了一个addressService对象,这就是自己挖的坑,我这个service中还有个成员变量 @Resource
private AddressMapper addressMapper ;
因为这个service是我自己创建的,所以这个成员变量spring是不会自动帮我注入的,所以一直空指针。。。。。。。。(难受,自己挖坑卖自己啊。。。。)
@Service
public class AddressService implements IAddressService {
@Resource
private AddressMapper addressMapper ;
/**
* 方法实现说明:通过用户的uid查找收货地址
* @author 翟波
* @param
* @return
* @exception
* @date 2019/1/2 10:56
*/
@Override
public List<Address> findAddrByUid(String uid) {
System.out.println("addressMapper::"+addressMapper);
return addressMapper.findAddrByUid(uid);
}
}
当时的异常:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.shop.mapper.AccountMapper.login
org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227)
org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:49)
org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
com.sun.proxy.$Proxy13.login(Unknown Source)
com.shop.service.AccountService.login(AccountService.java:26)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
com.sun.proxy.$Proxy16.login(Unknown Source)
com.shop.controller.AccountController.login(AccountController.java:83)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:867)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:951)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:853)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
还有就是没有按照开发规范来编写代码,我的cartController也不能直接去创建别的层的service,这也是犯了大忌,只有service之间才可以横向的调用,哎,记录一下,以后少干这事吧,哈哈。。。