spring+springmvc+mybatis+jqugrid+layui项目整合配置文件

本文介绍了如何将Spring、SpringMVC、MyBatis与JQugrid、LayUI整合,并提供了配置文件如applicationContext、applicationContext-tx、springmvc.xml等的具体代码段,详细讲解了整合过程中遇到的问题和解决方案。
摘要由CSDN通过智能技术生成

ssm整合过程中遇到的问题:

1.springmvc 不实现其他类的情况下 获取userService controller层添加private usrService(忽略)

2.sqlSessionFactory required(控制台报错提示)    --mabits配置文件加个文件头

3.代码自动生成RestController注解要修改成(Controller)(页面不显示内容)

4.代码自动生成界面需要调整mysql5.1

5.dao service sqlSessionFactory找不到(控制台报错提示)  一般是mybatis配置的原因

6. INFO com.alibaba.druid.pool.DruidDataSource.init() --{dataSource-1} inited
无影响,暂不解决

7.Date类型数据处理   $!date.format('yyyy-MM-dd HH:mm:ss ', $!list.createTime)
	@DateTimeFormat(pattern = "yyyy-MM-dd")将客户端提交的字符串转换为Date类型
	@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")将Date类型转换为指定格式字符串
	适用于表单输入的含有日期Date类型数据

日期添加不能在sql语句中写now,应该在controller中setUpdateTime等日期类型

8.405 action前面加/   post转put有一个隐藏的input

9.See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.(控制台报错提示)
xml文件错误


具体代码部分:

1.dependies

<!--spring依赖包    11个-->
<!-- spring核心包,springbean包, springcontext包,spring表达式包,springAOP包 -->
<!-- springAspects包,springJDBC包,spring事务包,spring对web的支持,springwebMVC-->
<!-- spring-context-support velocity --!>

<!--mybatis依赖包   3个-->
<!-- mybatis依赖, mybatis分页,Mybatis与spring整合包  -->

<!--数据库依赖包     2个  -->
<!--mysql,德鲁伊连接池-->

<!--javaweb依赖包   3个-->
<!--servlet-api,jsp-api,jstl-->

<!--插件依赖包      6个-->
<!--上传组件包,jackson(333个个个),hibernate的验证框架,log4j  -->

<!-- velocity模板语言支持包 2个-->
<!--  velocity,velocitytools  -->

2.applicationContext.xml

1.引入资源配置文件
2.引入德鲁伊连接池
	2.1连接配置数据库
	2.2连接配置德鲁伊

3.applicationContext-tx.xml

1.事务管理器
2.事务详情
3.事务切入点

4.springmvc.xml

1.注解扫描
2.注解驱动
3.视图解析器
4.格式化与类型转换服务
5.静态资源
6.文件上传解析器
7.配置拦截器

jqugrid部分
1.jqugrid 修改赋值必须用attr,不能用val()


spring

applicationContext.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"
        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">

    <!--注解-->
    <context:component-scan base-package="com.erdospro">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>


    <!--数据库-->
    <!-- 1.引入资源配置文件 -->
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- 2.引入德鲁伊连接池 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <!--  2.1.数据库配置   -->
        <property name="driverClassName" value="${jdbc.mysql.driver}"/>
        <property name="url" value="${jdbc.mysql.url}"/>
        <property name="username" value="${jdbc.mysql.username}"/>
        <property name="password" value="${jdbc.mysql.password}"/>
        <!--2.2德鲁伊配置-->
        <property name="initialSize" value="${druid.initialSize}"/>
        <property name="minIdle" value="${druid.minIdle}"/>
        <property name="maxActive" value="${druid.maxActive}"/>
        <property name="maxWait" value="${druid.maxWait}"/>
    </bean>


    <!--mybatis-->
    <!--  mybatis的sqlSessionFactory对象  -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--   数据源     -->
        <property name="dataSource" ref="dataSource"/>
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <props>
                            <prop key="helperDialect">mysql</prop>
                        </props>
                    </property>
                </bean>
            </array>
        </property>


        <!--    别名    -->
        <property name="typeAliasesPackage" value="com.erdospro.dao"/>
        <!--    加载mapper映射文件,可以使用通配符    -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    </bean>
    <!--mapper代理对象的扫描器-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!--   扫描基础包     -->
        <property name="basePackage" value="com.erdospro.dao"/>
        <!--    注入sqlsessionFactory    -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>


    <!-- google kaptcha的相关配置-->
    <bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">
        <property name="config">
            <bean class="com.google.code.kaptcha.util.Config">
                <constructor-arg>
                    <props>
                        <!-- 是否有边框 可选yes 或者 no -->
                        <prop key="kaptcha.border">yes</prop>
                        <!-- 边框颜色 -->
                        <prop key="kaptcha.border.color">105,179,90</prop>
                        <!-- 验证码文本字符颜色 -->
                        <prop key="kaptcha.textproducer.font.color">blue</prop>
                        <!-- 验证码文本字符大小 -->
                        <prop key="kaptcha.textproducer.font.size">30</prop>
                        <!-- 验证码图片的宽度 默认200 -->
                        <prop key="kaptcha.image.width">125</prop>
                        <!-- 验证码图片的高度 默认50 -->
                        <prop key="kaptcha.image.height">45</prop>
                        <!-- 验证码文本字符长度  默认为5 -->
                        <prop key="kaptcha.textproducer.char.length">4</prop>
                        <!-- 验证码文本字体样式  默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize)  -->
                        <prop key="kaptcha.textproducer.font.names">微软雅黑</prop>
                    </props>
                </constructor-arg>
            </bean>
        </property>
    </bean>

</beans>

applicationContext-tx.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:tx="http://www.springframework.org/schema/tx"
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.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.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">


    <!-- 事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 注入数据源-->
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 事务-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!-- 配置事务属性-->
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
            <tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
            <tx:method name="add*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
            <tx:method name="update*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
            <tx:method name="edit*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
            <tx:method name="del*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
            <tx:method name="delete*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
            <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="list*" propagation="SUPPORTS" read-only="true"/>
            <!-- 事务属性应用于方法的名称,*表示所有方法-->
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>
    <!-- 事务切入点-->
    <aop:config>
        <aop:pointcut id="exp" expression="execution(* com.erdospro.service.*Impl.*(..))"/>
        <!-- 将切点表达式与事务建立联系-->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="exp"/>
    </aop:config>


    <jdbc:embedded-database id="dataSource"/>
</beans>

sringmvc.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"
        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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">


    <!-- 注解扫描   -->
    <context:component-scan base-package="com.erdospro.controller"/>

    <!--注解驱动-->
    <mvc:annotation-driven conversion-service="conversionService" />


    <!--velocity配置-->
    <bean 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值