1.1 环境准备

java环境:

  • jdk1.7.0_72
  • eclipse indigo
  • springmvc版本:spring3.2

 所需要的jar包:

  • 数据库驱动包:mysql5.1
  • mybatis的jar包
  • mybatis和spring整合包
  • log4j包
  • dbcp数据库连接池包
  • spring3.2所有jar包
  • jstl包

 2018-02遇到的坑:在html中,表单命名应该是:< form  name="itemForm".....>结果,我错写成了<form id="itemsForm".....>然后,balabala两个小时过去了。知识不牢固造成的。希望以后会牢记此坑(<form name="itemsForm"....>

遇到的坑标记下:
package cn.itcast.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.itcast.ssm.po.ItemsCustom;
import cn.itcast.ssm.service.ItemsService; /**
遇到的坑标记下:如果在类的前面,使用@RequestMapping注解,指定了新的前缀,如:@RequestMapping("/items"),那么在页面访问页面时一定要加上去,如本例就是:localhost:8080/spring2018/items/queryItems.action
因为是直接拷的代码,没有详细看注释说明,在测试时,还一直按原地址:localhost:8080/spring2018/queryItems.action 访问,一直出错,原因找来找去整整折腾了10天,从放假前就找原因,一直找到春节初六上班,才明白;
*/
@Controller
//为了对url进行分类管理 ,可以在这里定义根路径,最终访问url是根路径+子路径
//比如:商品列表:/items/queryItems.action
@RequestMapping("/items")
public class ItemsController { @Autowired
private ItemsService itemsService; // 商品查询
@RequestMapping("/queryItems")
public ModelAndView queryItems(HttpServletRequest request) throws Exception {
//测试forward后request是否可以共享 System.out.println(request.getParameter("id")); // 调用service查找 数据库,查询商品列表
List<ItemsCustom> itemsList = itemsService.findItemsList(null); // 返回ModelAndView
ModelAndView modelAndView = new ModelAndView();
// 相当 于request的setAttribut,在jsp页面中通过itemsList取数据
modelAndView.addObject("itemsList", itemsList); // 指定视图
// 下边的路径,如果在视图解析器中配置jsp路径的前缀和jsp路径的后缀,修改为
// modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");
// 上边的路径配置可以不在程序中指定jsp路径的前缀和jsp路径的后缀
modelAndView.setViewName("items/itemsList"); return modelAndView; } }

spring 整合mybatis 学习笔记的更多相关文章

  1. Spring学习笔记:Spring整合Mybatis学习PPT(三:整合思路)

    三.Spring-Mybatis的整合思路

  2. Spring整合MybatisPlus学习笔记

    简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生 特性 无侵入:只做增强不做改变,引入它不会对现有 ...

  3. Mybatis学习笔记汇总(包括源码和jar包)

    博客整理 Mybatis学习笔记(一)--对原生jdbc中问题的总结 Mybatis学习笔记(二)--Mybatis框架 Mybatis学习笔记(三)--入门程序 MyBatis学习笔记(四)--入门 ...

  4. mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(附demo和搭建过程遇到的问题解决方法)

    文章介绍结构一览 一.使用maven创建web项目 1.新建maven项目 2.修改jre版本 3.修改Project Facts,生成WebContent文件夾 4.将WebContent下的两个文 ...

  5. mybatis学习笔记(六) -- maven+spring+mybatis从零开始搭建整合详细过程(下)

    继续 mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上) 五.使用监听器启动Spring容器 1.修改pom.xml文件,添加Spring-we ...

  6. mybatis 学习笔记(四):mybatis 和 spring 的整合

    mybatis 学习笔记(四):mybatis 和 spring 的整合 尝试一下整合 mybatis 和 spring. 思路 spring通过单例方式管理SqlSessionFactory. sp ...

  7. Spring学习笔记:Spring整合Mybatis(mybatis-spring.jar)(二:mybatis整合spring)

    http://blog.csdn.net/qq598535550/article/details/51703190 二.Spring整合mybatis其实是在mybatis的基础上实现Spring框架 ...

  8. Mybatis学习笔记之二(动态mapper开发和spring-mybatis整合)

    一.输入映射和输出映射 1.1 parameterType(输入类型) [传递简单类型] 详情参考Mybatis学习笔记之一(环境搭建和入门案例介绍) 使用#{}占位符,或者${}进行sql拼接. [ ...

  9. Spring学习总结(六)——Spring整合MyBatis完整示例

    为了梳理前面学习的内容<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>,做一个完整的示例完成一个简 ...

随机推荐

  1. Python中调用其他程序的方式

    前言 在Python中,可以方便地使用os模块来运行其他脚本或者程序,这样就可以在脚本中直接使用其他脚本或程序提供的功能,而不必再次编写实现该功能的代码.为了更好地控制运行的进程, 可以使用win32 ...

  2. Netty4 ServerBootstrap 初始化channelFactory ReflectiveChannelFactory

    只需要在启动之前传入你需要用的channel类型就可以了. ServerBootstrap初始化channelFactory过程: 最后我们再来看看这个channelFactory的使用场景:

  3. Selenium webdriver Java 封装与重用

    目的 1. 简化调用 WebDriver对页面的操作,需要找到一个WebElement,然后再对其进行操作,比较繁琐: WebElement element =driver.findElement(B ...

  4. [转]2年SQL Server DBA调优方面总结

      2年SQL Server DBA调优方面总结 当2年dba 我觉得,有些东西需要和大家分享探讨,先书单. 书单 1.<深入解析SQL Server 2008 系列> 这个就是mssql ...

  5. Instant Messaging for OpenERP v7

    This module is based on the socket.io real time implementation. It inherit Of the modules web_longpo ...

  6. 后缀数组suffix array

    倍增算法,时间复杂度O(nlogn) sa从小到大保存相对大小的下标 理解LSD,x数组,sa数组 char s[maxn]; int sa[maxn],t[maxn],t2[maxn],c[maxn ...

  7. javascript 清空数组的方法

    1,splice var ary = [1,2,3,4]; ary.splice(0,ary.length); console.log(ary); // 输出 [],空数组,即被清空了 2,lengt ...

  8. 自行控制loadrunner的socket协议性能测试 (转)

    一前言 二任务的提出 三实现方案讨论 四技术要点讲解 如何开始录制一个最简单的收发数据包脚本 写日志文件 一行一行读数据包文件 字符串转换为十六进制数据包 发送自己定义的数据包 接收数据包到自定义缓冲 ...

  9. 基于STC12C5A的MINI3216多功能点阵时钟

    代码地址如下:http://www.demodashi.com/demo/12862.html 基于STC12C5A的MINI3216多功能点阵时钟 硬件详解 PCB 硬件原理图 主控模块 max72 ...

  10. WP8控件进度条(ProgressBar)的使用

    --前台代码 <Grid x:Name="ContentPanel"  Grid.Row="1" Margin="0,0,24,0"& ...