資源簡(jiǎn)介
本案例是一個(gè)ssh整合案例,注意:本案例采用的框架是Spring+Springmvc+hibernate
代碼片段和文件信息
package?cn.lyl.ssm.controller;
import?java.util.List;
import?javax.servlet.http.HttpServletRequest;
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.RequestParam;
import?org.springframework.web.servlet.ModelAndView;
import?cn.lyl.ssm.po.Items;
import?cn.lyl.ssm.po.ItemsCustom;
import?cn.lyl.ssm.po.ItemsQueryVo;
import?cn.lyl.ssm.service.impl.ItemsService;
/**
?*?title:ItemsController
?*?Description:?商品的controller
?*?@author?李銀龍
?* 2017年8月5日
?* 下午9:24:40
?*/
@Controller
//為了對(duì)url進(jìn)行分類(lèi)管理,可以在這里定義根路徑,最終訪問(wèn)url是根路徑+子路徑
//比如:商品列表://items/queryItems.action
@RequestMapping(“/items“)
public?class?ItemsController?{
@Autowired
private?ItemsService?itemsService;
//商品查詢列表
//@RequestMapping實(shí)現(xiàn)方法和url進(jìn)行映射
//一般建議url和方法名寫(xiě)成一樣,queryItems可以加action后綴
@RequestMapping(“/queryItems“)
public?ModelAndView?queryItems(HttpServletRequest?requestItemsQueryVo?itemsQueryVo)?throws?Exception{
//調(diào)用service查詢數(shù)據(jù)庫(kù),查詢商品列表,這里使用靜態(tài)數(shù)據(jù)模擬
List?itemsList?=?itemsService.findItemsList(itemsQueryVo);
//返回ModelAndView
ModelAndView?modelAndView?=?new?ModelAndView();
//相當(dāng)于request的setAttribute方法
modelAndView.addobject(“itemsList“?itemsList);
//指定視圖
modelAndView.setViewName(“itemsList“);
return?modelAndView;
}
//商品信息修改頁(yè)面顯示
// @RequestMapping(“/editItems“)
//限制http請(qǐng)求方法
// @RequestMapping(value=“/editItems“method={RequestMethod.POSTRequestMethod.GET})
// public?ModelAndView?editItems()?throws?Exception{
//
// //調(diào)用service根據(jù)id查詢商品信息
// ItemsCustom?itemsCustom?=?itemsService.findItemsById(4);
//
// ModelAndView?modelAndView?=?new?ModelAndView();
// //將商品信息放到model中
// modelAndView.addobject(“itemsCustom“?itemsCustom);
// //指定視圖
// modelAndView.setViewName(“items/editItems“);
// return?modelAndView;
// }
//@RequestParam(value=“id“)里邊指定request傳入?yún)?shù)名稱(chēng)和形參進(jìn)行綁定。
//通過(guò)required屬性指定參數(shù)是否必須傳入
//通過(guò)defaultValue可以設(shè)置默認(rèn)值,如果id參數(shù)沒(méi)有傳入,將默認(rèn)值和形參綁定。
@RequestMapping(value=“/editItems“method={RequestMethod.POSTRequestMethod.GET})
public?String?editItems(Model?modelHttpServletRequest?request@RequestParam(value=“id“required=true)Integer?items_id)?throws?Exception{
//調(diào)用service根據(jù)id查詢商品信息
ItemsCustom?itemsCustom?=?itemsService.findItemsById(items_id);
//通過(guò)形參中的model將model數(shù)據(jù)傳到頁(yè)面
//此方法和modelandview方法相當(dāng)
model.addAttribute(“itemsCustom“itemsCustom);
return?“editItems“;
}
//商品信息修改提交
@RequestMapping(“/editItemsSubmit“)
public?String?editItemsSubmit(HttpServletRequest?requestInteger?idItemsCustom?itemsCustom)?throws?Exception{
//調(diào)用service更新商品信息,頁(yè)面需要將商品信息傳到此方法
//重定向
itemsService.updateItems(id?itemsCustom);
// return?“redirect:queryItems.action“;
return?“succe
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件???????1283??2017-08-08?10:11??sshDemo\.classpath
?????文件?????????12??2017-08-08?09:45??sshDemo\.git\COMMIT_EDITMSG
?????文件????????254??2017-08-08?09:46??sshDemo\.git\config
?????文件?????????23??2017-08-07?19:09??sshDemo\.git\HEAD
?????文件???????9592??2017-08-08?09:45??sshDemo\.git\index
?????文件????????775??2017-08-08?09:45??sshDemo\.git\logs\HEAD
?????文件????????775??2017-08-08?09:45??sshDemo\.git\logs\refs\heads\master
?????文件????????447??2017-08-08?09:50??sshDemo\.git\logs\refs\remotes\origin\master
?????文件????????663??2017-08-07?19:09??sshDemo\.git\ob
?????文件??????36548??2017-08-07?19:09??sshDemo\.git\ob
?????文件????????138??2017-08-07?19:09??sshDemo\.git\ob
?????文件??????17204??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????674649??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????????21??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????????61??2017-08-07?19:09??sshDemo\.git\ob
?????文件???????1256??2017-08-07?19:09??sshDemo\.git\ob
?????文件????????474??2017-08-07?21:02??sshDemo\.git\ob
?????文件?????334090??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????????45??2017-08-07?19:09??sshDemo\.git\ob
?????文件???????6656??2017-08-07?19:09??sshDemo\.git\ob
?????文件????????317??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????367783??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????981837??2017-08-07?19:09??sshDemo\.git\ob
?????文件????1455490??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????715290??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????442781??2017-08-07?19:09??sshDemo\.git\ob
?????文件?????????58??2017-08-07?19:09??sshDemo\.git\ob
?????文件???????1395??2017-08-07?19:09??sshDemo\.git\ob
?????文件????????101??2017-08-07?19:09??sshDemo\.git\ob
?????文件???????9486??2017-08-07?19:09??sshDemo\.git\ob
............此處省略346個(gè)文件信息
評(píng)論
共有 條評(píng)論