如何搭建SSM(SpringMvc+mybatis+Spring)java web工程

No.1   首先将web工程结构建好

1.1.1 开发环境介绍

 在这里我是采用的是MySQL数据库 

  编译器版本采用的是jdk使用的是1.8

 开发工具是使用的是eclipse Mars版本

  web容器采用的是tomcat 版本是7.0版本 

 

  在这里我将我自己写好的Demo工程目录结构截图展示出来方便大家新建项目

这张图图片清晰地将我的工程清晰地展示出来,先简单介绍下吧 ,项目主包是以com.cntv开始的 。在之下又分为好几个子包,分别是mapper、controller、service、dao、mapper、logs、config、base、entity、test包,其中controller包是负责接收前台请求执行部分业务逻辑的action,熟悉struts框架的应该知道Action哈 在这里我就不详细说了。mapper包主要是负责mybatis框架实体映射,config包是主要存储项目配置文件。  其他的包就不一一介绍了,都是些常规的包。

 

NO.2  准备好相应的jar包

这里我是采用Spring是.2.0版本 mybatis是3.3.0版本的
 
图中框选的jar包是一些依赖性jar包   不要以为这就是完整的jar包   还有呢....

 

到此为止 jar包已准备完毕  现在就来开始准备框架的相关的配置了  首先是spring+mybatis关联的配置

NO.3 配置框架相关功能的配置文件

在src目录中config文件夹中新建spring-mybatis.xml文件 ,通过这个文件集成并关联Spring+mybatis框架

 

[java]  view plain  copy
 
 print?
  1. <span style="font-size: 14px;"><</span><span style="font-size:18px;">?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:mvc="http://www.springframework.org/schema/mvc"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans    
  7.         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
  8.         http://www.springframework.org/schema/context    
  9.         http://www.springframework.org/schema/context/spring-context-3.1.xsd    
  10.         http://www.springframework.org/schema/mvc    
  11.         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">  
  12.     <span style="color:#ff0000;"><!-- 自动扫描 --></span>  
  13.     <context:component-scan base-package="com.cntv" />  
  14.     <span style="color:#ff0000;"><!-- 引入配置文件 --></span>  
  15.     <bean id="propertyConfigurer"  
  16.         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  17.         <property name="location" value="classpath:jdbc.properties" />  
  18.     </bean>  
  19.   
  20.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
  21.         destroy-method="close">  
  22.         <property name="driverClassName" value="${driver}" />  
  23.         <property name="url" value="${url}" />  
  24.         <property name="username" value="${username}" />  
  25.         <property name="password" value="${password}" />  
  26.         <span style="color:#ff0000;"><!-- 初始化连接大小 --></span>  
  27.         <property name="initialSize" value="${initialSize}"></property>  
  28.         <span style="color:#ff0000;"><!-- 连接池最大数量 --></span>  
  29.         <property name="maxActive" value="${maxActive}"></property>  
  30.         <span style="color:#ff0000;"><!-- 连接池最大空闲 --></span>  
  31.         <property name="maxIdle" value="${maxIdle}"></property>  
  32.         <span style="color:#ff0000;"><!-- 连接池最小空闲 --></span>  
  33.         <property name="minIdle" value="${minIdle}"></property>  
  34.         <span style="color:#ff0000;"><!-- 获取连接最大等待时间 --></span>  
  35.         <property name="maxWait" value="${maxWait}"></property>  
  36.     </bean>  
  37.   
  38.     <span style="color:#ff0000;"><!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --></span>  
  39.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  40.         <property name="dataSource" ref="dataSource" />  
  41.         <span style="color:#ff0000;"><!-- 自动扫描mapping.xml文件 --></span>  
  42.         <property name="mapperLocations" value="classpath:com/cntv/mapper/*.xml"></property>  
  43.     </bean>  
  44.   
  45.     <span style="color:#ff0000;"><!-- DAO接口所在包名,Spring会自动查找其下的类 --></span>  
  46.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  47.         <property name="basePackage" value="com.cn.hnust.dao" />  
  48.         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
  49.     </bean>  
  50.   
  51.     <span style="color:#ff0000;"><!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --></span>  
  52.     <bean id="transactionManager"  
  53.         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  54.         <property name="dataSource" ref="dataSource" />  
  55.     </bean>  
  56.   
  57. </beans></span>  

 

 

 

紧接着在src下config包下新建jdbc.properties文化  把数据库的配置放在这个配置文件里面

 

[html]  view plain  copy
 
 print?
  1. <span style="font-size:18px;">driver=com.mysql.jdbc.Driver  
  2. url=jdbc:mysql://125.221.225.113:3306/<span style="color:#ff0000;">db_zsl</span>  
  3. username=demao  
  4. password=demao  
  5. #定义初始连接数  
  6. initialSize=0  
  7. #定义最大连接数  
  8. maxActive=20  
  9. #定义最大空闲  
  10. maxIdle=20  
  11. #定义最小空闲  
  12. minIdle=1  
  13. #定义最长等待时间  
  14. maxWait=60000</span>  

 

说明:第一行是加载jdbc驱动地址 

第二行是连接数据库 加红色字体是数据库名字  前面是Ip地址+mysql数据库端口号

userName是数据库连接用户名

password是连接数据库密码

 

接下来配置SpringMvc相关的配置 

还是跟之前一样,在src目录下的config文件夹中新建spring-mvc.xml配置文件 

 这个文件主要是负责Mvc架构视图,前后台数据交互等。

 

[html]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  
  4.  xmlns:context="http://www.springframework.org/schema/context"  
  5.  xmlns:mvc="http://www.springframework.org/schema/mvc"  
  6.  xsi:schemaLocation="http://www.springframework.org/schema/beans    
  7.     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd    
  8.     http://www.springframework.org/schema/context    
  9.     http://www.springframework.org/schema/context/spring-context-3.1.xsd    
  10.     http://www.springframework.org/schema/mvc    
  11.     http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">  
  12.     <span style="color:#ff0000;"><!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --></span>  
  13.     <context:component-scan base-package="com.cntv.controller" />  
  14.     <span style="color:#ff0000;"><!--避免IE执行AJAX时,返回JSON出现下载文件 --></span>  
  15.     <bean id="mappingJacksonHttpMessageConverter"  
  16.       
  17.         class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
  18.         <property name="supportedMediaTypes">  
  19.             <list>  
  20.                 <value>text/html;charset=UTF-8</value>  
  21.             </list>  
  22.         </property>  
  23.     </bean>  
  24.     <span style="color:#ff0000;"><!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 --></span>  
  25.     <bean  
  26.         class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
  27.         <property name="messageConverters">  
  28.             <list>  
  29.                 <ref bean="mappingJacksonHttpMessageConverter" ></ref><span style="color:#ff0000;">   <!-- JSON转换器 --></span>  
  30.             </list>  
  31.         </property>  
  32.     </bean>   
  33.     <span style="color:#ff0000;"><!-- 定义跳转的文件的前后缀 ,视图模式配置--></span>  
  34.     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  35.         <span style="color:#ff0000;"><!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 --></span>  
  36.         <property name="prefix" value="/" />  
  37.         <property name="suffix" value=".jsp" />  
  38.     </bean>  
  39.     <span style="color:#ff0000;"><!-- 配置文件上传,如果没有使用文件上传可以不用配置,当然如果不配,那么配置文件中也不必引入上传组件包 --></span>  
  40.       <!--  <bean id="multipartResolver"    
  41.         class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    
  42.         默认编码  
  43.         <property name="defaultEncoding" value="utf-8" />    
  44.         文件大小最大值  
  45.         <property name="maxUploadSize" value="10485760000" />    
  46.         内存中的最大值  
  47.         <property name="maxInMemorySize" value="40960" />    
  48.     </bean> -->  
  49. </beans></span></span>  

 

最后配置web.xml文件

项目总配置文件将spring-mybatis.xml和spring-mvc.xml集成到web.xml里面

[java]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns="http://java.sun.com/xml/ns/javaee"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  
  5.     version="3.0">  
  6.     <display-name>Archetype Created Web Application</display-name>  
  7.     <span style="color:#ff0000;"><!-- Spring和mybatis的配置文件 --></span>  
  8.     <context-param>  
  9.         <param-name>contextConfigLocation</param-name>  
  10.         <param-value>classpath:spring-mybatis.xml</param-value>  
  11.     </context-param>  
  12.     <span style="color:#ff0000;"><!-- 编码过滤器 --></span>  
  13.     <filter>  
  14.         <filter-name>encodingFilter</filter-name>  
  15.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  16.         <async-supported>true</async-supported>  
  17.         <init-param>  
  18.             <param-name>encoding</param-name>  
  19.             <param-value>UTF-8</param-value>  
  20.         </init-param>  
  21.     </filter>  
  22.     <filter-mapping>  
  23.         <filter-name>encodingFilter</filter-name>  
  24.         <url-pattern>/</url-pattern>  
  25.     </filter-mapping>  
  26.     <span style="color:#ff0000;"><!-- Spring监听器 --></span>  
  27.     <listener>  
  28.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  29.     </listener>  
  30.     <span style="color:#ff0000;"><!-- 防止Spring内存溢出监听器 --></span>  
  31.     <listener>  
  32.         <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
  33.     </listener>  
  34.     <!-- Spring MVC servlet -->  
  35.     <servlet>  
  36.         <servlet-name>SpringMVC</servlet-name>  
  37.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  38.         <init-param>  
  39.             <param-name>contextConfigLocation</param-name>  
  40.             <param-value>classpath:spring-mvc.xml</param-value>  
  41.         </init-param>  
  42.         <load-on-startup>1</load-on-startup>  
  43.         <async-supported>true</async-supported>  
  44.     </servlet>  
  45.     <servlet-mapping>  
  46.         <servlet-name>SpringMVC</servlet-name>  
  47.         <span style="color:#ff0000;"><!-- 此处可以可以配置成*.do,对应struts的后缀习惯 --></span>  
  48.         <url-pattern>*.do</url-pattern>  
  49.     </servlet-mapping>  
  50.     <welcome-file-list>  
  51.         <welcome-file>/index.jsp</welcome-file>  
  52.     </welcome-file-list>  
  53.     <span style="color:#ff0000;"><!-- 配置SESSION超时,单位是分钟 --></span>  
  54.     <session-config>  
  55.         <session-timeout>15</session-timeout>  
  56.     </session-config>  
  57.   
  58. </web-app></span>  


NO.4 收官完成 测试框架能否正常运行

直到这里我们已经把框架配置好了现在我们就要写一些实在的东西了 把接口和service定一下

4.1.1  定义一个接口 

在dao包下新建IUserDao.java类
[java]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><span style="font-size:18px;">package com.cntv.dao;  
  2.   
  3. import org.springframework.stereotype.Repository;  
  4.   
  5. import com.cntv.entity.User;  
  6. @Repository  
  7. public interface IUserDao {  
  8.     int deleteByPrimaryKey(Integer id);  
  9.   
  10.     int insert(User record);  
  11.   
  12.     int insertSelective(User record);  
  13.   
  14.     User selectByPrimaryKey(Integer id);  
  15.   
  16.     int updateByPrimaryKeySelective(User record);  
  17.   
  18.     int updateByPrimaryKey(User record);  
  19. }</span></span>  

4.1.2 定义一个service接口

 同样的在service包下新建IUserService.java类
[java]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><span style="font-size:18px;">package com.cntv.service;  
  2.   
  3. import com.cntv.entity.User;  
  4.   
  5. public interface IUserService {  
  6.     public User getUserById(int userId);  
  7. }</span><span style="font-size:14px;">  
  8. </span></span>  
 

4.1.3定义一个javaBean

 

[java]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><span style="font-size:18px;">package com.cntv.entity;  
  2. public class User {  
  3.     private Integer id;  
  4.   
  5.     private String userName;  
  6.   
  7.     private String password;  
  8.   
  9.     private Integer age;  
  10.   
  11.     public Integer getId() {  
  12.         return id;  
  13.     }  
  14.   
  15.     public void setId(Integer id) {  
  16.         this.id = id;  
  17.     }  
  18.   
  19.     public String getUserName() {  
  20.         return userName;  
  21.     }  
  22.   
  23.     public void setUserName(String userName) {  
  24.         this.userName = userName == null ? null : userName.trim();  
  25.     }  
  26.   
  27.     public String getPassword() {  
  28.         return password;  
  29.     }  
  30.   
  31.     public void setPassword(String password) {  
  32.         this.password = password == null ? null : password.trim();  
  33.     }  
  34.   
  35.     public Integer getAge() {  
  36.         return age;  
  37.     }  
  38.   
  39.     public void setAge(Integer age) {  
  40.         this.age = age;  
  41.     }  
  42.       
  43. }</span></span>  

 

4.1.4 定义一个mapper.xml实体映射 

很简单,在mapper文件夹下新建UserMapper.xml配置文件
[html]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >  
  3. <mapper namespace="com.cntv.dao.IUserDao" >  
  4.   <resultMap id="BaseResultMap" type="com.cntv.entity.User" >  
  5.     <id column="id" property="id" jdbcType="INTEGER" />  
  6.     <result column="user_name" property="userName" jdbcType="VARCHAR" />  
  7.     <result column="password" property="password" jdbcType="VARCHAR" />  
  8.     <result column="age" property="age" jdbcType="INTEGER" />  
  9.   </resultMap>  
  10.   <sql id="Base_Column_List" >  
  11.     id, user_name, password, age  
  12.   </sql>  
  13.   <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >  
  14.     select   
  15.     <include refid="Base_Column_List" />  
  16.     from user_t  
  17.     where id = #{id,jdbcType=INTEGER}  
  18.   </select>  
  19.   <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >  
  20.     delete from user_t  
  21.     where id = #{id,jdbcType=INTEGER}  
  22.   </delete>  
  23.   <insert id="insert" parameterType="com.cntv.entity.User" >  
  24.     insert into user_t (id, user_name, password,   
  25.       age)  
  26.     values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},   
  27.       #{age,jdbcType=INTEGER})  
  28.   </insert>  
  29.   <insert id="insertSelective" parameterType="com.cntv.entity.User" >  
  30.     insert into user_t  
  31.     <trim prefix="(" suffix=")" suffixOverrides="," >  
  32.       <if test="id != null" >  
  33.         id,  
  34.       </if>  
  35.       <if test="userName != null" >  
  36.         user_name,  
  37.       </if>  
  38.       <if test="password != null" >  
  39.         password,  
  40.       </if>  
  41.       <if test="age != null" >  
  42.         age,  
  43.       </if>  
  44.     </trim>  
  45.     <trim prefix="values (" suffix=")" suffixOverrides="," >  
  46.       <if test="id != null" >  
  47.         #{id,jdbcType=INTEGER},  
  48.       </if>  
  49.       <if test="userName != null" >  
  50.         #{userName,jdbcType=VARCHAR},  
  51.       </if>  
  52.       <if test="password != null" >  
  53.         #{password,jdbcType=VARCHAR},  
  54.       </if>  
  55.       <if test="age != null" >  
  56.         #{age,jdbcType=INTEGER},  
  57.       </if>  
  58.     </trim>  
  59.   </insert>  
  60.   <update id="updateByPrimaryKeySelective" parameterType="com.cntv.entity.User" >  
  61.     update user_t  
  62.     <set >  
  63.       <if test="userName != null" >  
  64.         user_name = #{userName,jdbcType=VARCHAR},  
  65.       </if>  
  66.       <if test="password != null" >  
  67.         password = #{password,jdbcType=VARCHAR},  
  68.       </if>  
  69.       <if test="age != null" >  
  70.         age = #{age,jdbcType=INTEGER},  
  71.       </if>  
  72.     </set>  
  73.     where id = #{id,jdbcType=INTEGER}  
  74.   </update>  
  75.   <update id="updateByPrimaryKey" parameterType="com.cntv.entity.User" >  
  76.     update user_t  
  77.     set user_name = #{userName,jdbcType=VARCHAR},  
  78.       password = #{password,jdbcType=VARCHAR},  
  79.       age = #{age,jdbcType=INTEGER}  
  80.     where id = #{id,jdbcType=INTEGER}  
  81.   </update>  
  82. </mapper></span></span>  
这个文件就包含CRUD操作 sql语句在标签中都有定义 ,需要注意的是这里面sql语句用到的一些参数全部是从dao层获取的
mapper文件是映射数据库表对应的javaBean实体 mapper中可以写sql语句 很方便。

4.1.5 定义一个service实现类

在service包下serviceImpl包下新建UserServiceImpl类
[java]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><span style="font-size:18px;">package com.cntv.service.serviceImpl;  
  2. import javax.annotation.Resource;  
  3. import javax.servlet.http.HttpServletResponse;  
  4.   
  5. import org.springframework.context.ApplicationContext;  
  6. import org.springframework.context.support.ClassPathXmlApplicationContext;  
  7. import org.springframework.stereotype.Service;  
  8. import com.cntv.dao.IUserDao;  
  9. import com.cntv.entity.User;  
  10. import com.cntv.service.IUserService;  
  11. import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;  
  12. @Service  
  13. public class UserServiceImpl implements IUserService {  
  14.     @Resource  
  15.     private IUserDao userDao;  
  16.     @Override  
  17.     public User getUserById(int userId) {  
  18.         // TODO Auto-generated method stub  
  19.         return this.userDao.selectByPrimaryKey(userId);  
  20.     }  
  21.    public static void main(String[] args) {  
  22.        ApplicationContext ca= new ClassPathXmlApplicationContext("spring-mybatis.xml");  
  23.        UserServiceImpl u=(UserServiceImpl) ca.getBean("userServiceImpl");  
  24.       User ue= u.getUserById(12);  
  25.        System.out.println("用户名:"+ue.getUserName());  
  26. <span>    </span>   System.out.println("用户密码:"+ue.getPassword());  
  27. }  
  28. public IUserDao getUserDao() {  
  29.     return userDao;  
  30. }  
  31. public void setUserDao(IUserDao userDao) {  
  32.     this.userDao = userDao;  
  33. }  
  34.      
  35. }</span><span style="font-size:14px;">  
  36. </span></span>  
 

 

4.1.6 定义一个controller

在src目录下的controller包下新建一个controller,在这里我新建的是UserController.java
[java]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><span style="font-size:18px;">package com.cntv.controller;  
  2.   
  3. import javax.annotation.Resource;  
  4. import javax.servlet.http.HttpServletRequest;  
  5. import javax.servlet.http.HttpServletResponse;  
  6.   
  7. import org.apache.coyote.Request;  
  8. import org.springframework.http.HttpRequest;  
  9. import org.springframework.stereotype.Controller;  
  10. import org.springframework.ui.Model;  
  11. import org.springframework.web.bind.annotation.RequestMapping;  
  12. import org.springframework.web.bind.annotation.ResponseBody;  
  13. import org.springframework.web.servlet.ModelAndView;  
  14.   
  15. import com.cntv.entity.User;  
  16. import com.cntv.service.serviceImpl.UserServiceImpl;  
  17.   
  18. @Controller  
  19. public class UserController {  
  20.     @Resource  
  21.     private UserServiceImpl userService;  
  22.     @RequestMapping("test.do")  
  23.     public ModelAndView  testCon(HttpServletRequest request,Model model){  
  24.         System.out.println("hello");  
  25.         System.out.println(request.getParameter("id"));  
  26.         User u=userService.getUserById(new Integer(request.getParameter("id")));  
  27.         System.out.println(u.getUserName());  
  28.         ModelAndView mod=new ModelAndView();  
  29.         mod.setViewName("success");  
  30.         return mod;  
  31.     }  
  32.     /** 
  33.      * @deprecated 
  34.      * 根据前台封装的javaBean属性进行封装  这里是进行User对象的封装 
  35.      * 测试后台是否能正常能拿到数据        
  36.      * @param user 获取前台穿过来的对象 
  37.      * @param request 
  38.      * @return 
  39.      */  
  40.     @RequestMapping("submit.do")  
  41.     public String testBean(User user,HttpServletRequest request){  
  42.         System.out.println("========+"+user.getUserName()+"..."+user.getPassword());  
  43.         return "success";  
  44.           
  45.     }  
  46.     public UserServiceImpl getUserService() {  
  47.         return userService;  
  48.     }  
  49.     public void setUserService(UserServiceImpl userService) {  
  50.         this.userService = userService;  
  51.     }  
  52.       
  53. }</span><span style="font-size:14px;">  
  54. </span></span>  
 

 

 

Ok!!!现在就来测试下吧后台数据库和service层到底能不能打通吧  

 

再来对照下数据库中数据吧!!

 经过测试持久层和业务层是能互通的 测试通过!!!!

  

啦啦啦!  现在测试前后台数据能不能互通了  ....

 
前端新建一个jsp测试页面  测试请求和数据能不能到达后台controller里面
在这里我新建的是eg.jsp
 
[html]  view plain  copy
 
 print?
  1. <span style="font-size:18px;"><span style="font-size:18px;"><%@ page language="java" contentType="text/html; charset=utf-8"  
  2.     pageEncoding="utf-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  7. <script type="text/javascript" src="js/jquery-1.7.js"></script>  
  8. <title>Insert title here</title>  
  9. </head>  
  10. <body>  
  11. <input id="inp" type="hidden" maxlength="20">  
  12. <h2>Test formMait</h2>  
  13. <form action="submit.do" method="post" >  
  14. 账户<input type="text" name="userName"><br>  
  15. 密码<input type="text" name="password"><br>  
  16. <button>提交</button>  
  17.   
  18. </form>  
  19. <script type="text/javascript">  
  20.  $(function(){  
  21.     // alert("json hello");  
  22.        
  23.  })  
  24.  function clicBt(){  
  25.      console.log("hello friends!!!")  
  26.      $.ajax({  
  27.            type: "POST",  
  28.            url: "test.do?id="+$("#inp").val(),  
  29.            data: "name=John&location=Boston",  
  30.            success: function(msg){  
  31.              alert("china is hello  and you are okau!");  
  32.            }  
  33.         });  
  34.        
  35.        
  36.  }  
  37. </script>  
  38. </body>  
  39. </html></span></span>  

重点来了!!!测试前台数据和请求能不能到达后台
 
>>>>>>输入http://127.0.0.1:8080/SpringMybat/eg.jsp 进入测试页面 

到后台来看看控制台有什么反应木有??

 

哈哈哈  前台输入的账号密码成功到达后台controlLee并打印出来了!

测试圆满成功!!!

 

现在我们就可以根据业务需求来做我们自己想做的事情了,后台框架搭建完成了,如果需要其他相关配置可以查阅其他资料完成配置。

 

 

项目全部jar包下载地址是:http://download.csdn.net/detail/jason763/9646274 下载这个文件就可以了   按照我说的配置就可以用了。

项目源码地址为:http://download.csdn.net/detail/jason763/9646304 如有需要可以下载源码。

注:本博文为博主原创,未经允许不得转载。

转载于:https://www.cnblogs.com/andriod2016/articles/6524907.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值