使用的是JDK1.7+tomcat7开发的ssm项目,地址栏输入login和register可以正确进入登录和注册页面不报错。在注册页面正确输入完用户名后由ajax提交到UserController进行验证:
//注册验证 @RequestMapping(value="/checkRegister",method=RequestMethod.POST) public void checkRegister(HttpServletRequest request, HttpServletResponse response,Users user,Model model){ try { System.out.println("已进入到注册检测模块!"); String cardId = request.getParameter("cardId"); cardId=usersService.getUserByCardId(cardId).getCardId(); PrintWriter out; out = response.getWriter(); out.write(JSONArray.fromObject(cardId).toString()); } catch (IOException e) { e.printStackTrace(); } }
不过控制台并没有输出“已进入注册检测模块!”这句话,而是直接报以下错误!
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${driverClass}'
### The error may exist in dao/UsersMapper.xml
### The error may involve dao.UsersMapper.getUserByCardId
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${driverClass}'] with root cause
java.lang.ClassNotFoundException: ${driverClass}
然后配置文件是在源文件夹中,源码是:
driverClass=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/mysql user=root password=As3014
DBCP数据源配置如下:
<!-- JNDI获取数据源(使用dbcp连接池) --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="singleton"> <property name="driverClassName" value="${driverClass}" /> <property name="url" value="${url}" /> <property name="username" value="${user}" /> <property name="password" value="${password}" /> </bean>
UserMapper类的代码为:
public interface UsersMapper{ @MapKey("id") public Map<Integer,Users> usersList(); public Users getUserByCardId(String cardId); public Users getUserByName(String name); public Integer insertUsers(Users user); public Integer deleteUsers(Users user); public Integer updateUsers(Users user); }
UserMapper.xml代码为:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="dao.UsersMapper"> <!-- 查询用户--> <select id="usersList" resultType="users" parameterType="users"> select * from users </select> <select id="getUserByName" resultType="users" parameterType="users"> select * from Users where name=#{name} </select> <select id="getUserByCardId" resultType="users" parameterType="users"> select * from Users where cardId=#{cardId} </select> <select id="insertUsers" parameterType="users"> insert into Users(cardId,name,gender,createTime,password,status) values( #{cardId},#{name},#{gender},#{createTime},#{password},#{status} ) </select> <select id="updateUsers" parameterType="users"> update users set name=#{name},gender=#{gender},createTime=#{createTime},password=#{password},status=#{status} where cardId=#{cardId} </select> <select id="deleteUsers" parameterType="users"> delete from users where cardId=#{cardId} </select> </mapper>
数据库驱动包为:mysql-connector-java-5.1.7-bin.jar之前项目中还有5.1.0和5.1.26版本的mysql驱动,与现状错误是一样的。driverClass这个类没问题的,在jar包可以找得到。
我找来找去也发现不了是哪的问题,请求各位大神帮忙指点!!!
执着小哥
相关分类