当前位置: 代码迷 >> J2EE >> springmvc+myibatis+spring调整示例(仅供参考)
  详细解决方案

springmvc+myibatis+spring调整示例(仅供参考)

热度:409   发布时间:2016-04-21 22:06:46.0
springmvc+myibatis+spring整合示例(仅供参考)
闲来无事,为了学习easyui+ztree,于是写了一个demo,
服务端使用springmvc+myibatis+spring实现,
界面截图
登录:

home页面:

列表页面:

tree页面:

添加页面:

服务器代码部分截图:
spring配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

    <context:annotation-config/>
    <tx:annotation-driven transaction-manager="transactionManager" />
    <context:component-scan base-package="com.school.portal" />

    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />             
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/school?useUnicode=true&amp;characterEncoding=utf8" />
<property name="username" value="root" />
<property name="password" value="123456" />
<property name="maxActive" value="80" />
<property name="maxIdle" value="20" />
<property name="maxWait" value="3000" />
</bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />           
        <property name="typeAliasesPackage" value="com.school.portal.entity" />    
        <property name="mapperLocations" value="classpath*:mapper/*.xml" />
        <property name="configLocation" value="classpath:myibatis-config.xml"></property>
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.school.portal.dao" />
        <property name="markerInterface" value="com.school.portal.dao.BasicMapper"/>    
    </bean>
    
    <bean id="springContext" class="com.school.portal.SpringContext"/>
    
    <import resource="spring/spring-mvc.xml"/>
</beans>


springmvc配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

<!-- DispatcherServlet Context: defines this servlet's request-processing 
infrastructure -->
<context:component-scan base-package="com.school.portal.web.controller" />

<interceptors>
<interceptor>
<mapping path="/**" />
<beans:bean class="com.school.portal.web.interceptor.UserDetailInterceptor" />
</interceptor>
</interceptors>



<!-- 完成请求和注解POJO的映射 -->
  相关解决方案