发表于: 2018-10-13 23:47:25

2 439


今天完成的事情:

看完ssm框架整合的视频,尝试把Springmvc跟任务一的Spring+mybatis的demo整合

(1)由于任务一的demo不是web项目,所以把任务一的相关文件copy到一个web的项目中,并引入相关的jar包

(2)加入Springmvc的webapp文件,controller层和spring-mvc.xml文件,并引入相关的jar包

(3)在web.xml中加入Spring+mybatis的上下文

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:springConfig/spring-db.xml,classpath:mybatisConfig/mybatis-config.xml</param-value>
</context-param>

(4)以一个jsp文件为模板编写一个简单的表格

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Spring MVC Hello World</title>
</head>

<body>
  <h2>All Students in System</h2>
  <table border="1">
     <tr>
        <th>id</th>
        <th>create_at</th>
        <th>update_at</th>
        <th>student_name</th>
        <th>qq</th>
        <th>profession</th>
        <th>admission_date</th>
        <th>graduated_from</th>
        <th>student_id</th>
        <th>daily_link</th>
        <th>make_wishes</th>
        <th>coaching_senior</th>
        <th>approach</th>
     </tr>

     <c:forEach var="student" items="${student}">
<tr>
           <td>${student.id}</td>
           <td>${student.createAt}</td>
           <td>${student.updateAt}</td>
           <td>${student.studentName}</td>
           <td>${student.qq}</td>
           <td>${student.profession}</td>
           <td>${student.admissionDate}</td>
           <td>${student.graduatedFrom}</td>
           <td>${student.studentId}</td>
           <td>${student.dailyLink}</td>
           <td>${student.makeWishes}</td>
           <td>${student.coachingSenior}</td>
           <td>${student.approach}</td>
        </tr>
     </c:forEach>
</table>

</body>
</html>

2.运行时遇到一个问题,注解的重复扫描(这个bug花费的差不多半天的时间)

文件结构如下

(1)在spring-mybatis的配置文件中扫描注册bean,其中包括扫描并注册了controller层

(2)在spring-mvc的配置文件中需要扫描注册controller层(这会导致controller层的二次注册?不是很清楚是不是扫描一次就注册一次?或者是先扫描spring-mybatis的配置文件并注册了bean,然后spring-mvc就不能注册bean了?



明天计划的事情:

继续完成ssm框架的整合并实现增删改查


遇到的问题:

对接收页面信息和输出信息到页面的方法不了解


收获如上



返回列表 返回列表
评论

    分享到