4.4 mybatis-config.xml

  这部分可以配置也可以不配置。

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings>
<setting name="cacheEnabled" value="true" />
<setting name="lazyLoadingEnabled" value="true" />
<setting name="aggressiveLazyLoading" value="true" />
<setting name="multipleResultSetsEnabled" value="true" />
<setting name="useColumnLabel" value="true" />
<setting name="useGeneratedKeys" value="false" />
<setting name="autoMappingBehavior" value="PARTIAL" />
<setting name="defaultExecutorType" value="SIMPLE" />
<setting name="defaultStatementTimeout" value="25000" />
</settings>
19 </configuration>

4.5 spring-mvc.xml 配置

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> <!-- 扫描控制器包 -->
<!-- @Service用于标注业务层组件、 @Controller用于标注控制层组件、@Repository用于标注数据访问组件,即DAO组件。而@Component泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。-->
<context:component-scan base-package="com.vivebest.controller" /> <!-- Enables the Spring MVC @Controller programming model -->
<!-- 启动springmvc注解 -->
<mvc:annotation-driven /> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射,解决@ResponseBody乱码问题 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
<!--视图解析的配置-->
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" /><!--controller层中返回页面是可以不加.jsp后缀-->
</bean>
</beans>

5.Spring和Mybatis测试

  5.1 测试分为两种(1.使用junit测试   2.编写测试类)

    我用的是编写测试类测试    

 package com.vivebest.test;

 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.vivebest.service.CustomerService; public class Test {
private ApplicationContext ac = null;
public static void main(String[] args) {
Test test=new Test();
test.before();
}
public void before() {
ac = new ClassPathXmlApplicationContext("applicationContext.xml"); //引入配置文件
CustomerService customerService= (CustomerService) ac.getBean("customerService");//需要注意这里的customerService 是在service中使用@Service(“customerService”)一致
System.out.println(customerService.getAllCustomer());
/* CustomerService TellerService= (CustomerService) ac.getBean("TellerService");
System.out.println(TellerService);*/
}
}

6.SSM整合测试

  编写controller层

 package com.vivebest.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.ResponseBody;
import com.vivebest.entity.Customer;
import com.vivebest.service.CustomerService; @Controller//标明为控制层
@RequestMapping("/customer")//相当于路径
public class CustomerController{ @Autowired
private CustomerService customerService; /**
* 客户登陆
*/
@RequestMapping(value ="/customerLogin", method = RequestMethod.POST)
public String customerLogin(Model model,HttpServletRequest req){
List<Customer> cusList=customerService.getAllCustomer();
Customer custom=cusList.get(0);
req.setAttribute("custome", custom);
System.out.println(custom);
return "finally";
}
}

编写jsp页面,在jsp页面中我遇到了一个小问题,即

在使用jstl.jar中 因为

"org.apache.jasper.JasperException: This absolute uri (http://java.sun.com/jsp/jstl/core ) cannot be resolved in either web.xml or the jar files deployed with this application "

由于JSTL1.0和JSTL1.1的声明语句不一样。

这个问题在另一边文章中我做了总结,大家可以去游览。

启动工程,测试成功!

Spring+SpringMvc+Mybatis 框架的搭建(二)的更多相关文章

  1. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(2 配置spring-dao和测试)

    用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 搭建目录环境和依赖) 四:在\resources\spring 下面 ...

  2. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建二:配置MyBatis 并测试(1 构建目录环境和依赖)

    引言:在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一   的基础上 继续进行项目搭建 该部分的主要目的是测通MyBatis 及Spring-dao ...

  3. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试

    这一部分的主要目的是 配置spring-service.xml  也就是配置spring  并测试service层 是否配置成功 用IntelliJ IDEA 开发Spring+SpringMVC+M ...

  4. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目

    一:创建maven web项目er

  5. Spring+SpringMvc+Mybatis框架集成搭建教程

    一.背景 最近有很多同学由于没有过SSM(Spring+SpringMvc+Mybatis , 以下简称SSM)框架的搭建的经历,所以在自己搭建SSM框架集成的时候,出现了这样或者那样的问题,很是苦恼 ...

  6. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建四:配置springmvc

    在用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建三:配置spring并测试的基础上 继续进行springmvc的配置 一:配置完善web.xml文件

  7. SSM(Spring+SpringMVC+Mybatis)框架环境搭建(整合步骤)(一)

    1. 前言 最近在写毕设过程中,重新梳理了一遍SSM框架,特此记录一下. 附上源码:https://gitee.com/niceyoo/jeenotes-ssm 2. 概述 在写代码之前我们先了解一下 ...

  8. 【Spring】Spring+SpringMVC+MyBatis框架的搭建

    1,SSM的简介 SSM(Spring+SpringMVC+MyBatis)框架集由Spring.SpringMVC.MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架. 其中s ...

  9. Spring+SpringMvc+Mybatis 框架的搭建(一)

    本文是因为实习结束后学习到了新的技术,想写下来和更多人交流.开发中遇到的问题我也会一一说明,希望有更多人可以互相探讨,加入到一起来. 1. Spring+SpringMvc +Mybatis 的作用有 ...

  10. Spring+SpringMvc+Mybatis框架集成搭建教程二(依赖配置及框架整合)

    依赖导入以及框架整合 (1).打开项目的pom.xml文件,声明依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" x ...

随机推荐

  1. QQ好友在线/离线,怎么测试?

    即时通讯是目前internet上最为流行的通讯方式,各种各样的即时通讯软件也层出不穷,那么今天主要针对QQ好友在线状态/QQ群友在线状态功能出发,一起思考其中的实现原理以及我们如何去测试此功能? 当大 ...

  2. 一步到位分布式开发Zookeeper实现集群管理

    说到分布式开发Zookeeper是必须了解和掌握的,分布式消息服务kafka .hbase 到hadoop等分布式大数据处理都会用到Zookeeper,所以在此将Zookeeper作为基础来讲解. Z ...

  3. [LeetCode] 01 Matrix 题解

    题意 # 思路 我一开始的时候想的是嘴 # 实现 ```cpp // // include "../PreLoad.h" class Solution { public: /** ...

  4. 配置Windows Server 2012服务器远程连接支持多人同时登陆

    1.运行输入gpedit.msc 进入组策略 2.计算机配置--管理模版--windows组件--远程桌面服务--远程桌面会话主机--连接 3.找到限制连接的数量,启用,并改为100. 4.找到 将远 ...

  5. @RequestParam--SpringMVC 注解系列文章(一)

    概述 RequestParam 注解是使用 SpringMVC 开发过程中,比较常用的一个注解,用于映射请求参数. 代码 package rex.springmvc.handlers; import ...

  6. spring定时器的使用

    Spring定时任务在有的项目中起到很关键的作用,它允许你通过配置来指定特定时间去调用特定类的特定方法. 一. 分类 1.作业类需要继承特定的类.特定的类有: org.springframework. ...

  7. eclipse项目导入到android studio中文乱码处理

    由于eclipse项目是gbk编码,Android studio默认用的是utf-8. 就会导致代码中的汉字,注释全部显示为乱码. 解决方法:在module的bulid.gradle中加入: comp ...

  8. 组件Prop验证

    <div id="example"> <kkk></kkk> </div> <script src="https:/ ...

  9. The 15th UESTC Programming Contest Preliminary G - GC?(X,Y) cdoj1564

    地址:http://acm.uestc.edu.cn/#/problem/show/1564 题目: G - GC?(X,Y) Time Limit: 3000/1000MS (Java/Others ...

  10. IOS开发创建开发证书及发布App应用(八)——使用Application Loader工具上传应用

    8.使用Application Loader工具上传应用 继续第七步在iTunes所创建的应用,打开应用,如下图 点击详情按钮进去之后,单击右上角Ready to Upload Binary按钮,如下 ...