SSH版本:spring4.3.2 + struts2.3.16 + hibernate5.1.0数据库使用的mysql
具体搭建方法建议参考:http://blog.csdn.net/zhuanzhe117/article/details/48014545
http://blog.csdn.net/zndxlxm/article/details/8714383
两篇不错的文章,讲解的很详细,并附有具体代码。
需要注意的问题:
1.数据库名不能为username,系统会自动匹配为本机电脑名。
2. 找不到dataSource的类 Build path is incomplete. Cannot find class file for com/mchange/v2/ser/ Ind
解决:导入mchange-commons-java-0.2.3.1.jar
3.hibernate4之后,使用openSession()代替getCurrentSession();
4.表名 is not mapped [FROM USER S WHERE S.ID = :id]
USER应为数据库表对应的对象名,S.ID id应为对象的属性,而不是数据库的字段。应该为:FROM User S WHERE S.id=:id
5.java中转json的问题
使用json必须的包(目前使用的版本):
commons-lang-2.6.jar
commons-logging-1.1.3.jar
json-lib-2.4-jdk15.jar
ezmorph-1.0.6.jar
commons-collections-3.2.2.jar
commons-beanutils-1.9.2.jar
commons-logging-1.1.3.jar
json-lib-2.4-jdk15.jar
ezmorph-1.0.6.jar
commons-collections-3.2.2.jar
commons-beanutils-1.9.2.jar
错误及对应包名
出现ava.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException错误因为没有导入commons-lang-2.4.jar文件或版本不对。(需导入2.x版本 (commons-lang-2.4.jar)不删除3.x版本)
出现java.lang.NoClassDefFoundError: net/sf/json/JSONObject错误因为没有导入json-lib-2.3-jdk15.jar
出现java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher错误是因为没有导入ezmorph.jar文件或版本不对。
出现java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap错误是因为没有导入commons-collections.jar文件或版本不对。
出现java.lang.ClassNotFoundException: org.apache.commons.beanutils.DynaBean
是因为没有导入commons-beanutils-1.9.2.jar文件或版本不对。
出现java.lang.NoClassDefFoundError: net/sf/json/JSONObject错误因为没有导入json-lib-2.3-jdk15.jar
出现java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher错误是因为没有导入ezmorph.jar文件或版本不对。
出现java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap错误是因为没有导入commons-collections.jar文件或版本不对。
出现java.lang.ClassNotFoundException: org.apache.commons.beanutils.DynaBean
是因为没有导入commons-beanutils-1.9.2.jar文件或版本不对。