1、
在使用JDBC时,想着把创建连接的代码放在Dao的构造函数中。
public UserDao() {
connection = DbConnect.getDBconnection();
}
结果每操作一次Dao,第二次再操作的时候就报“不允许对已经关闭的连接操作!”。(比如注册之后再登陆)
我的理解是:因为每次操作后都会关闭连接,而这个Dao的生命周期还没结束,构造函数之会执行一次。所以第二次获取连接的时候就会报错。
finally {
DbConnect.closeDB(connection, pStatement, rs);
}
这个可以用在用户长时间未操作中,如果出现这个错误,就要重新登陆。
2、
PreparedStatement类引入的包是import java.sql.PreparedStatement;
import com.mysql.jdbc.PreparedStatement;包还没用过。具体公共未知,应该大同小异。
3、
使用JSTL标签的时候要记得引入标签库!
<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core”%>
4、
该异常表示@RequestMapping的注解中出现了重复,不能区分从哪个入口进入
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping’: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘userOperate’ method
public java.lang.String cap.controller.UserOperate.register()
to { /index/register}: There is already ‘indexController’ bean method
5、
启动eclipse时,pom.xml报错:
Multiple annotations found at this line:
- Project configurator “com.springsource.sts.ide.maven.core.springProjectConfigurator” required by plugin execution “org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-compile)”
is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration.
在eclipse中,安装m2e-apt插件
点击Open Catalog 找到m2e-apt。
6、
在mybatis中。
List、Map类型会先执行new语句,再赋值
(不能用null来判断是否有数据,应该用size大小)
普通类不会执行new语句,直接赋值
例如
if(adminDao.login(auser) != null && adminDao.login(auser).size() > 0)
7、
需要配置MyBatis的依赖包和数据库连接池。不然application.xml会报错
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.18.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
8、
在XML中“&”符合需要写成“&”!
<property name="url" value="jdbc:mysql://localhost:3306/electronicbusiness?characterEncoding=utf8&useSSL=true" />