ssm中需要注意的一些坑!!
1.index.jsp放在webcontent目录下,不要放在web-inf文件夹下面!!!
2.配置视图解析器时的“/”使用参考:
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
- ${pageContext.request.contextPath } 相当于 WebContent
4.在使用
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="${pageContext.request.contextPath }/js/jquery-3.3.1.min.js"></script>
<link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
</head>
<body>
<table class="table table-striped">
<thead>
<th>id<th/>
<th>username<th/>
<th>password<th/>
</thead>
<tbody>
<c:forEach items="${itemList}" var="item">
<tr>
<td>${item.id}</td>
<td>${item.username}</td>
<td>${item.password}</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
5.有时候th和td的内容对不齐,是因为放在了下面。把直接放在下面就可以了,就对齐了。如:
<thead>
<th>id</th>
<th>username</th>
<th>password</th>
</thead>
6.Could not resolve placeholder ‘jdbc.driver’ in string value “${jdbc.driver}“
<context:property-placeholder location="classpath:/db.properties" **ignore-unresolvable="true"**/>
7.在连接数据库时经常出现错误,在经过一番折腾后,我总结下常见的坑。
(1)
(2)db.properties的变量名一定要一一对应,不能马虎。比如db.properties的jdbc.jdbcUrl带在value中时要写${jdbc.jdbcUrl},而不是${jdbc.Url}。我就是在这里马虎了,浪费了很多时间和精力
(3)
<!-- 读取配置文件 数据库 -->
<context:property-placeholder location="classpath:db.properties" ignore-unresolvable="true"/>
<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<!-- 这里一定要是name="user",不能是name="username"!!! -->
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
db.properties:
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm
jdbc.username=root
jdbc.password=root
8.mapper.xml中注意:
返回类型用:resultType,不是resultMap!!!这是个大坑!!
还没有评论,来说两句吧...