SpringMVC用户信息的action层UserInfoAction的类

package com.gxa.bj.action;

import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.gxa.bj.model.UserInfo;
import com.gxa.bj.service.UserInfoService;
@Controller
public class UserInfoAction {
private UserInfoService userInfoService;

public UserInfoService getUserInfoService() {
return userInfoService;
}
public void setUserInfoService(UserInfoService userInfoService) {
this.userInfoService = userInfoService;
}
public List<UserInfo> getList(UserInfo u){
return userInfoService.getList(u);
}
@RequestMapping(value="/getalluser.action")
public ModelAndViewgetAllUser(){
ModelAndView modelView = new ModelAndView();
List<UserInfo> list = userInfoService.getList(null);
modelView.addObject("users",list);
modelView.setViewName("/index.jsp");
return modelView;

}

@RequestMapping(value="/login.action",method={RequestMethod.POST})
public String login(String txtUserName,String txtUserPwd) throws ServletException, IOException{
//req.setCharacterEncoding("utf-8");//设置参数的编码格式
// String userName = req.getParameter("txtUserName");
// String userPwd = req.getParameter("txtUserPwd");
// System.out.println("用户名:"+userName);
// System.out.println("密码:"+userPwd);
UserInfo u  = userInfoService.getLogin(txtUserName, txtUserPwd);
if(u!=null){
return "forward:/search.jsp";
}else{
return "redirect:/login.jsp";
}
}
@RequestMapping(value="/reg.action")
public void reg(UserInfo u){
System.out.println("用户名:"+u.getUserName());
}
@RequestMapping(value="/searchusers.action",method={RequestMethod.GET})
public ModelAndView searchUsers(String userName){
ModelAndView model = new ModelAndView();
UserInfo u = new UserInfo();
u.setUserName(userName);
List<UserInfo> list = userInfoService.getList(u);
model.addObject("users",list);
model.setViewName("/search.jsp");
return model;
}
@RequestMapping(value="/detail/{id}",method={RequestMethod.GET})
public ModelAndView detail(@PathVariable(value="id") Integer id){
System.out.println("hello");
ModelAndView model = new ModelAndView();
   UserInfo u = userInfoService.getUserInfo(id);
   model.addObject("user", u);
   model.setViewName("/user.jsp");
return model;
}

}

猜你喜欢

转载自blog.csdn.net/y1991024/article/details/51883182