@Controller
public class ItemsController {

@Autowired
private ItemsService itemService;

/**
 * 实现页面数据的展示
 * @return
 */
@RequestMapping("/itemList.action")
public ModelAndView getItemsList(){
    List<Items> itemList = itemService.getAllItems();
    ModelAndView view = new ModelAndView();
    view.setViewName("itemList");
    view.addObject("itemList", itemList);
    return view;
}



/**
 * 实现页面数据的修改操作,通过request来获取参数
 */
/*@RequestMapping("/itemEdit.action")
public ModelAndView skipToEdit(HttpServletRequest request,HttpServletResponse response,HttpSession session){
    
    String parameter = request.getParameter("id");
    Integer id = new Integer(parameter);
    Items items = itemService.selectItemByPrimaryKey(id);
    System.out.println(parameter);
    ModelAndView view = new ModelAndView();
    view.setViewName("editItem");
    view.addObject("item", items);
    return view;
}
*/

/**
 * 简单参数绑定
 * @param id
 * @return
 */
/*@RequestMapping("/itemEdit.action")
public ModelAndView skipToEdit(Integer  id){
    Items items = itemService.selectItemByPrimaryKey(id);
    ModelAndView view = new ModelAndView();
    view.setViewName("editItem");
    view.addObject("item", items);
    return view;
}*/




/**
 * 通过model来实现我们的模型和视图
 * @param id
 * @param model
 * @return
 */
@RequestMapping("/itemEdit.action")
public String skipToEdit(@RequestParam(value="id",defaultValue="2",required=true)Integer ids,Model model){
    Items items = itemService.selectItemByPrimaryKey(ids);
    model.addAttribute("item", items);
    return "editItem";
}


/**
 * 修改操作,通过手动转码,实现乱码的解决
 * @throws UnsupportedEncodingException 
 */
/*@RequestMapping("/updateitem.action")
public String updateItem(Items items,HttpServletRequest request) throws UnsupportedEncodingException{
    
    String parameter = request.getParameter("name");
    String parameter2 = request.getParameter("detail");
    
    String name = new String(parameter.getBytes("iso-8859-1"), "utf-8");
    String detail = new String(parameter2.getBytes("iso-8859-1"), "utf-8");
    
    items.setName(name);
    items.setDetail(detail);
    itemService.updateItem(items);
    return "success";
}*/

/**
 * 修改操作,通过filter过滤器来实现我们乱码的解决
 * @throws UnsupportedEncodingException 
 */
@RequestMapping("/updateitem.action")
public String updateItem(Items items) throws UnsupportedEncodingException{
    itemService.updateItem(items);
    return "success";
}



/**
 * 查询操作
 */
@RequestMapping("/queryitem.action")
public ModelAndView queryItem(QueryVo vo){
    
    System.out.println(vo.getItems().getName());
    System.out.println(vo.getItems().getDetail());
    ModelAndView view = new ModelAndView();
    view.setViewName("success");
    
    
    return view;
}
 没有了 service 

评论已关闭

暂无评论