日期:2014-05-17 浏览次数:20790 次
package com.itsum.springmvcpt.bg.test.controller;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import com.itsum.springmvcpt.bg.test.benas.dtos.User;
import com.itsum.springmvcpt.bg.test.services.Iservices.Iuserservice;
import com.itsum.springmvcpt.bg.test.services.serviceImpl.UserService;
@Controller
public class UserController {
private Iuserservice service;
public Iuserservice getService() {
return service;
}
public void setService(Iuserservice service) {
this.service = service;
}
@RequestMapping("/welcome")
public ModelAndView welcome(){
ModelAndView mv=new ModelAndView();
System.out.println("service: "+service);
List<User> list=service.findByLimit(10);
mv.addObject("list", list);
mv.setViewName("welcome");
return mv;
}
}
package com.itsum.springmvcpt.bg.test.services.Iservices;
import java.util.List;
import com.itsum.springmvcpt.bg.test.benas.dtos.User;
public interface Iuserservice {
public List<User> findByLimit(int limit);
}
package com.itsum.springmvcpt.bg.test.services.serviceImpl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.itsum.springmvcpt.bg.test.benas.dtos.User;
import com.itsum.springmvcpt.bg.test.dao.Idaos.UserDao;
import com.itsum.springmvcpt.bg.test.services.Iservices.Iuserservice;
@Service("service")
public class UserService implements Iuserservice{
private UserDao dao;
public UserDao getDao() {
return dao;
}
public void setDao(UserDao dao) {
this.dao = dao;