springmvc与mybatis整合之实现商品列表
生活随笔
收集整理的這篇文章主要介紹了
springmvc与mybatis整合之实现商品列表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
需求
實現商品查詢列表,從mysql數據庫查詢商
品信息。
. DAO開發
使用逆向工程,生成代碼
注意修改逆向工程的配置文件
ItemService接口
public interface ItemService {/*** 查詢商品列表* * @return*/List<Item> queryItemList();}. ItemServiceImpl實現類
@Service public class ItemServiceImpl implements ItemService {@Autowiredprivate ItemMapper itemMapper;@Overridepublic List<Item> queryItemList() {// 從數據庫查詢商品數據List<Item> list = this.itemMapper.selectByExample(null);return list;}}ItemController
@Controller public class ItemController {@Autowiredprivate ItemService itemService;/*** 顯示商品列表* * @return*/@RequestMapping("/itemList")public ModelAndView queryItemList() {// 獲取商品數據List<Item> list = this.itemService.queryItemList();ModelAndView modelAndView = new ModelAndView();// 把商品數據放到模型中modelAndView.addObject("itemList", list);// 設置邏輯視圖modelAndView.setViewName("itemList");return modelAndView;}}測試
訪問url:
http://127.0.0.1:8080/springmvc-web/itemList.action
總結
以上是生活随笔為你收集整理的springmvc与mybatis整合之实现商品列表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C字节对齐与C++类对象内存布局
- 下一篇: s3c2440移植MQTT