Springmvc+mybatis

web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <servlet>
    <servlet-name>weiyin</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:weiyin-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>weiyin</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
    <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
  </listener>
  <listener>
    <description>requestListener</description>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
  <welcome-file-list>
    <welcome-file></welcome-file>
  </welcome-file-list>
  <error-page>
    <error-code>404</error-code>
    <location>/404.html</location>
  </error-page>
</web-app>

Spring配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <context:component-scan base-package="com.weiyin">
        <context:exclude-filter type="regex" expression="com\.weiyin\.mobile\.controller..*" />
    </context:component-scan>

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
            </list>
        </property>
    </bean>


    <!-- =================================================================== -->
    <!-- AOP: Configuration and Aspects                                      -->
    <!-- =================================================================== -->
    <aop:config>
        <aop:advisor id="managerTx" advice-ref="txAdvice"
            pointcut="execution(* *..*Service.*(..))" order="0" />
    </aop:config>

    <tx:advice id="txAdvice">
        <tx:attributes>
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="change*" propagation="REQUIRED" />
            <tx:method name="import*" propagation="REQUIRED" />
            <tx:method name="create*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="modify*" propagation="REQUIRED" />
            <tx:method name="resume*" propagation="REQUIRED" />
            <tx:method name="execute*" propagation="REQUIRED" />
            <tx:method name="execute*" propagation="REQUIRED" />
            <tx:method name="send*" propagation="REQUIRED" />
            <tx:method name="*Login" propagation="REQUIRED" />
            <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>

    <!-- JNDI DataSource for J2EE environments -->
    <!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/appfuse"/>-->
     <!--
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/oa2"></property>
    </bean>
     -->
     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass">
            <value>${jdbc.driverClassName}</value>
        </property>
        <property name="jdbcUrl">
            <value>${jdbc.url}</value>
        </property>
        <property name="user">
            <value>${jdbc.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
        <property name="initialPoolSize">
            <value>5</value>
        </property>
        <property name="minPoolSize">
            <value>5</value>
        </property>
        <property name="maxPoolSize">
            <value>10</value>
        </property>
        <property name="acquireIncrement">
            <value>5</value>
        </property>
        <property name="maxIdleTime">
            <value>30</value>
        </property>
        <property name="maxStatements">
            <value>1000</value>
        </property>
        <property name="numHelperThreads">
            <value>5</value>
        </property>        
        <property name="unreturnedConnectionTimeout">
            <value>600</value>
        </property>
        <property name="debugUnreturnedConnectionStackTraces">
            <value>true</value>
        </property>
    </bean>

    <bean id="sqlSessionFactory"
        class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation">
            <value>classpath:sqlMapConfig.xml</value>
        </property>
        <property name="dataSource" ref="dataSource" />
    </bean>

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

    <!-- 缓存 -->
    <bean id="cache" class="com.weiyin.cache.LocalCache">
        <constructor-arg value="0"/>
    </bean>
    
</beans>

weiyin-servlet.xml 

<?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:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
    
<!--     <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="webBindingInitializer">
            <bean class="com.mwteck.crm.util.BindingInitializer" />
        </property>
    </bean> -->
    
    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">    
        <property name="converters">    
            <list>    
                <bean class="com.weiyin.util.DateConverter" />  
               <!--  <bean class="com.mwteck.crm.util.StringConverter" />  -->  
            </list>    
        </property>    
    </bean>  
    
    <mvc:annotation-driven conversion-service="conversionService">
         <mvc:argument-resolvers>
            <bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
            <bean class="org.springframework.mobile.device.site.SitePreferenceWebArgumentResolver" />
        </mvc:argument-resolvers>
    </mvc:annotation-driven>

    <!-- 扫描所有的controller -->
    <context:component-scan base-package="com.weiyin.mobile.controller" />
    <context:component-scan base-package="com.weiyin.util" />
    
    <task:executor id="executor" pool-size="5" />
    <task:scheduler id="scheduler" pool-size="5" />
    <task:annotation-driven scheduler="scheduler"
        executor="executor" />

    <bean id="exceptionResolver"
        class="com.weiyin.exception.BaseExceptionHandler">
        <property name="defaultErrorView" value="error_all" />
    </bean>
    
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="5000000000" />
        <property name="maxInMemorySize" value="4096"/>
    </bean>

    <!-- <mvc:interceptors>
        <bean class="com.mwteck.crm.filter.SecurityInterceptor" />
    </mvc:interceptors>     -->
    
     <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven>
        <mvc:argument-resolvers>
            <bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
            <bean class="org.springframework.mobile.device.site.SitePreferenceWebArgumentResolver" />
        </mvc:argument-resolvers>
    </mvc:annotation-driven>
    <mvc:interceptors>
        <!-- On pre-handle, resolve the device that originated the web request -->
        <bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />
        <!-- On pre-handle, manage the user's site preference (declare after DeviceResolverHandlerInterceptor) -->
        <bean class="org.springframework.mobile.device.site.SitePreferenceHandlerInterceptor" />
    </mvc:interceptors>
    <bean class="org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver">
        <constructor-arg>
            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix" value="/WEB-INF/page/"></property>
                <property name="suffix" value=".jsp"></property>
            </bean>
        </constructor-arg>
        <property name="enableFallback" value="true" />
        <property name="mobilePrefix" value="mobile/" />
    </bean>
</beans>

sqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="cacheEnabled" value="false"/>
        <setting name="lazyLoadingEnabled" value="flase"/>
        <setting name="multipleResultSetsEnabled" value="true"/>
        <setting name="useColumnLabel" value="true"/>
        <setting name="useGeneratedKeys" value="false"/>
        <setting name="defaultExecutorType" value="REUSE"/>
        <!--
        <setting name="enhancementEnabled" value="false"/>
        <setting name="defaultStatementTimeout" value="25000"/>
        -->
    </settings>
    <typeAliases>
        <!-- 抽象POJO基类 -->
        <typeAlias alias="BaseObject" type="com.weiyin.base.BaseObject" />
        <typeAlias alias="TreeObject" type="com.weiyin.base.TreeObject" />
        
        <!-- 系统管理 -->
        <typeAlias alias="TMerchant" type="com.weiyin.entity.TMerchant" />
        
    </typeAliases>
    
    <plugins>
        <plugin interceptor="se.spagettikod.optimist.impl.OptimisticLockingInterceptor">
        </plugin>
    </plugins>
        
    <mappers>
        <!-- 全局sql配置 -->
        <mapper resource="Global.xml" />
        <!-- 系统管理 -->
        <mapper resource="com/weiyin/TMerchant.xml" />
    </mappers>
</configuration>

Global.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="Global">
    <resultMap id="BaseObjectMap" type="BaseObject">
        <id property="id" column="id" javaType="java.lang.Integer" jdbcType="INTEGER" />
    </resultMap>
    <resultMap id="BaseObjectMap_Long" type="BaseObject">
        <id property="id" column="id" javaType="java.lang.Long" jdbcType="BIGINT" />
    </resultMap>
    <resultMap id="BaseObjectMap_String" type="BaseObject">
        <id property="id" column="paramkey" javaType="java.lang.String" jdbcType="VARCHAR"  />
    </resultMap>
    <resultMap id="TreeObjectMap" type="TreeObject">
        <id property="id" column="id" javaType="java.lang.Integer"  jdbcType="INTEGER" />
        <result property="name" column="name" />
        <result property="parentId" column="parentid" javaType="java.lang.Integer" jdbcType="INTEGER" />
        <result property="parentIds" column="parentids" />
        <result property="nodeIndex" column="orderidx" />
    </resultMap>
    <update id="execute" parameterType="hashmap">
        ${sql}
    </update>
    <select id="queryOne" parameterType="hashmap" resultType="hashmap" >
        ${sql}
    </select>
    <select id="queryList" parameterType="hashmap" resultType="hashmap" >
        ${sql}
    </select>
</mapper>

TMerchant.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="com.weiyin.entity.TMerchant">
    
    <!-- 属性配置 -->
    <resultMap id="TMerchantMap" type="TMerchant" extends="Global.BaseObjectMap">
        <result property="floginPwd" column="floginPwd" />
        <result property="fmobilePhone" column="fmobilePhone" />
    </resultMap>
    
    <!-- 新增 -->
    <insert id="insert" parameterType="TMerchant">
        INSERT INTO tmerchant (fmobilePhone,floginPwd)
        VALUES (#{floginPwd},#{fmobilePhone})
    </insert>
    <!-- 根据FPhone查询TMerchant对象 -->
    <select id="getTMerchantByPhone" parameterType="string" resultType="TMerchant">
            SELECT tmerchant.FID, tmerchant.FMerchantNo, tmerchant.FBranchCompanyID, tmerchant.FAgencyID, tmerchant.FDealerID, tmerchant.FMerchantName,
            tmerchant.FLoginName, tmerchant.FLoginPwd, tmerchant.FSalt, tmerchant.FName, tmerchant.FIdentity, tmerchant.FEmail, tmerchant.FPostCode,
            tmerchant.FCityID, tmerchant.FPhone, tmerchant.FMobilePhone, tmerchant.FAdress, tmerchant.FRegisterDate, tmerchant.FRates, tmerchant.FIsAudit,
            tmerchant.FAuditDate, tmerchant.FType, tmerchant.FStatus, tmerchant.FBusinessLicence, tmerchant.FCardForntPath, tmerchant.FCardBackPath,
            tmerchant.FIdentityForntPath, tmerchant.FIdentityBackPath, tmerchant.FOrgnizationCode, tmerchant.FTaxCertificate, tmerchant.FApproverer,
            tmerchant.FApproveTime, tmerchant.FReason, tmerchant.FMerchantID, tmerchant.FCashType, tmerchant.FisClicked, tmerchant.FverifyCode,
            tmerchant.FContractPic, tmerchant.FDoorPic, tmerchant.FCashierPic, tmerchant.FManagementPic, tmerchant.FHousePic, tmerchant.FThreePartiesPic
            FROM tmerchant
            WHERE tmerchant.FMobilePhone=#{fmobilePhone}        
    </select>    
    <!-- 查询 -->
    <select id="find" parameterType="map" resultMap="TMerchantMap">
        <include refid="findSql"/>
        
        <!-- <if test="title != null">
            and title = #{title}
        </if>
        <if test="content != null">
            and content = #{content}
        </if>
        <if test="owner != null">
            and owner = #{owner}
        </if> -->
    </select>
    
    <!-- 查询记录数 -->
    <select id="count" parameterType="map" resultType="long">
        SELECT COUNT(*) FROM (<include refid="findSql"/>) X
    </select>
    
    <sql id="findSql">
        select a.* FROM tmerchant
    </sql>
    
</mapper>



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!
提供的源码资源涵盖了python应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值