报错:
```org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.nowcoder.toutiao.dao.NewsDAO.selectByUserIdAndOffset
at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:214) ~[mybatis-3.4.0.jar:3.4.0]
at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:48) ~[mybatis-3.4.0.jar:3.4.0]
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59) ~[mybatis-3.4.0.jar:3.4.0]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) ~[mybatis-3.4.0.jar:3.4.0]
at com.sun.proxy.$Proxy60.selectByUserIdAndOffset(Unknown Source) ~[na:na]
at com.nowcoder.toutiao.servicr.NewsService.getLatestNews(NewsService.java:16) ~[classes/:na]
at com.nowcoder.toutiao.controller.HomeController.index(HomeController.java:30) ~[classes/:na]
其中 NewsService.java
package com.nowcoder.toutiao.servicr;
import com.nowcoder.toutiao.dao.NewsDAO;
import com.nowcoder.toutiao.model.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class NewsService {
@Autowired
private NewsDAO newsDAO;
public List<News> getLatestNews(int userId,int offset,int limit){
return newsDAO.selectByUserIdAndOffset(userId,offset,limit);
}
}
HomeController代码:
package com.nowcoder.toutiao.controller;
import com.nowcoder.toutiao.dao.NewsDAO;
import com.nowcoder.toutiao.model.News;
import com.nowcoder.toutiao.model.ViewObject;
import com.nowcoder.toutiao.servicr.NewsService;
import com.nowcoder.toutiao.servicr.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.jws.WebParam;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@Controller
public class HomeController{
@Autowired
NewsService newsService;
@Autowired
UserService userService;
@RequestMapping(path={"/","/index"},method={RequestMethod.GET,RequestMethod.POST})
public String index(Model model){
List<News> newsList=newsService.getLatestNews(0,0,10);
List<ViewObject> vos=new ArrayList<>();
for (News news:newsList){
ViewObject vo=new ViewObject();
vo.set("news",news);//vo里面可以放任何东西
vo.set("user",userService.getUser(news.getUserId()));
vos.add(vo);
}
model.addAttribute("vos",vos);
return "home";
}
}