当整合完,将项目部署到服务器时 Error creating bean with name 'filmTypeMapper' defined in file : 出现这个错误,一般都是mybatis的XML文件中的配置出现了错误
前端页面无法查出数据: 首先要分段寻找错误
1.查数据库连接(主要是看配置文件和spring.xml中数据源,sqlsessionfactory的配置)
2.如果连接正常,查看mybatis的mapper.xml的sql语句(对mybatis要进一步熟悉),测试是否能够查出数据
3.如果测试成功,则是向前端发送json数据时出错
(1)查看struts.xml是否写对(查看文档,如何进行json传输)
(2)查看是否导入了spring-json-plugin的包,注意要与spring核心包的版本一致
(3)如果上述的都没问题,则用firebug查看前端收到的响应
mybatis使用。
(1)定义一个映射的接口,列出方法名
(2)每个映射接口对应创建一个xml文件,注意命名空间要与映射接口的全类名相同
(3)注册mapper.xml文件,
如果是在mybatis.xml单独使用中配置如下两种方法:
<!-- xml方式读取映射信息 -->
<mapper resource="com/yc/mybatis/entity/StudentMapper.xml"/>
<!-- 注解方式的读取映射信息,要在接口上加上@service -->
<package name="com.yc.mybatis.mapper"/>
<mapper class="com.yc.mybatis.mapper.StudentMapper"/>
如果是spring+mybatis整合,如下配置:
<!-- mybatis与spring整合 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 资源路径 -->
<property name="dataSource" ref="dataSource"/>
<!-- 实体类路径 -->
<property name="typeAliasesPackage" value="com.yc.ssm.cinema.entity"/>
<!-- 扫描mybatis.xml -->
<property name="mapperLocations" value="classpath:mapper/*Mapper.xml"/>
</bean>
<!-- 配置映射接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.yc.ssm.cinema.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
前端页面无法查出数据: 首先要分段寻找错误
1.查数据库连接(主要是看配置文件和spring.xml中数据源,sqlsessionfactory的配置)
2.如果连接正常,查看mybatis的mapper.xml的sql语句(对mybatis要进一步熟悉),测试是否能够查出数据
3.如果测试成功,则是向前端发送json数据时出错
(1)查看struts.xml是否写对(查看文档,如何进行json传输)
(2)查看是否导入了spring-json-plugin的包,注意要与spring核心包的版本一致
(3)如果上述的都没问题,则用firebug查看前端收到的响应
(4)如果收到响应,但是不能显示,则看JSON数据和easyui定义的字段名是否一致(注意大小写)
mybatis使用。
(1)定义一个映射的接口,列出方法名
(2)每个映射接口对应创建一个xml文件,注意命名空间要与映射接口的全类名相同
(3)注册mapper.xml文件,
如果是在mybatis.xml单独使用中配置如下两种方法:
<!-- xml方式读取映射信息 -->
<mapper resource="com/yc/mybatis/entity/StudentMapper.xml"/>
<!-- 注解方式的读取映射信息,要在接口上加上@service -->
<package name="com.yc.mybatis.mapper"/>
<mapper class="com.yc.mybatis.mapper.StudentMapper"/>
如果是spring+mybatis整合,如下配置:
<!-- mybatis与spring整合 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 资源路径 -->
<property name="dataSource" ref="dataSource"/>
<!-- 实体类路径 -->
<property name="typeAliasesPackage" value="com.yc.ssm.cinema.entity"/>
<!-- 扫描mybatis.xml -->
<property name="mapperLocations" value="classpath:mapper/*Mapper.xml"/>
</bean>
<!-- 配置映射接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.yc.ssm.cinema.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>