spring 整合mybatis 学习笔记
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 学习笔记的更多相关文章
- Spring学习笔记:Spring整合Mybatis学习PPT(三:整合思路)
三.Spring-Mybatis的整合思路
- Spring整合MybatisPlus学习笔记
简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生 特性 无侵入:只做增强不做改变,引入它不会对现有 ...
- Mybatis学习笔记汇总(包括源码和jar包)
博客整理 Mybatis学习笔记(一)--对原生jdbc中问题的总结 Mybatis学习笔记(二)--Mybatis框架 Mybatis学习笔记(三)--入门程序 MyBatis学习笔记(四)--入门 ...
- mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(附demo和搭建过程遇到的问题解决方法)
文章介绍结构一览 一.使用maven创建web项目 1.新建maven项目 2.修改jre版本 3.修改Project Facts,生成WebContent文件夾 4.将WebContent下的两个文 ...
- mybatis学习笔记(六) -- maven+spring+mybatis从零开始搭建整合详细过程(下)
继续 mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上) 五.使用监听器启动Spring容器 1.修改pom.xml文件,添加Spring-we ...
- mybatis 学习笔记(四):mybatis 和 spring 的整合
mybatis 学习笔记(四):mybatis 和 spring 的整合 尝试一下整合 mybatis 和 spring. 思路 spring通过单例方式管理SqlSessionFactory. sp ...
- Spring学习笔记:Spring整合Mybatis(mybatis-spring.jar)(二:mybatis整合spring)
http://blog.csdn.net/qq598535550/article/details/51703190 二.Spring整合mybatis其实是在mybatis的基础上实现Spring框架 ...
- Mybatis学习笔记之二(动态mapper开发和spring-mybatis整合)
一.输入映射和输出映射 1.1 parameterType(输入类型) [传递简单类型] 详情参考Mybatis学习笔记之一(环境搭建和入门案例介绍) 使用#{}占位符,或者${}进行sql拼接. [ ...
- Spring学习总结(六)——Spring整合MyBatis完整示例
为了梳理前面学习的内容<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>,做一个完整的示例完成一个简 ...
随机推荐
- 客户端JavaScript加密数据,服务端Java解密数据
原文:http://blog.csdn.net/peterwanghao/article/details/43303807 在普通的页面提交时,如果没有使用SSL,提交的数据将使用纯文本的方式发送.如 ...
- Could not instantiate bean class [org.springframework.data.domain.Pageable]: Specified class is an interface解决方案
原文:http://pimin.net/archives/432 环境:Eclipse LUNA.Spring 4.1.1.或Spring 4.3.3.Spring Data Elasticsearc ...
- CSS3:绘制图形
CSS画图形,基本上所有的实现都是对边框的角度的调整及组合. 以下不包含兼容浏览器的前缀,请使用时在border-radius前加-moz-.-webkit- .... 1.正常得不得了的矩形 .sq ...
- jquery.mobile 中 collapsible-set collapsible listview 共同布局问题
最近项目用上了jquery.mobile这货,在手机上做点简单的显示.之前只知道有这个框架,没把玩过. 特别是事件绑定方面,相比桌面系统下浏览器用着各种不爽,不得要领. 如下图,在做后台系统时,一般左 ...
- selinux 是什么 (Linux)
SElinux是Linux安全加强工具.关闭用setenforce 0或者修改文件vim /etc/sysconfig/selinux 把SELINUX=enforcing 改为 SELINUX=di ...
- [TypeScript] Use the TypeScript "unknown" type to avoid runtime errors
The "any" type can be very useful, especially when adding types to an existing JavaScript ...
- Node.js nvshens图片批量下载爬虫 1.00
//====================================================== // www.nvshens.com图片批量下载Node.js爬虫1.00 // 此程 ...
- Spring AOP实现拦截转发控制
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ...
- Django——如何使用Template以及如何向template传递变量
如何使用模板系统 在Python代码中使用Django模板的最基本方式如下: 可以用原始的模板代码字符串创建一个 Template 对象, Django同样支持用指定模板文件路径的方式来创建 Temp ...
- react-native-storage + AsyncStorage 实现数据存储
1.组件封装 import Storage from 'react-native-storage'; import { AsyncStorage } from 'react-native'; cons ...