zoukankan      html  css  js  c++  java
  • 集成mybatis(一)

    Spring MVC框架集成mybatis

    1.配置Mybatis-Spring项目需要这么几步:

    ·配置数据源

    ·配置SqlSessionFactory

    ·配置Mapper

    ·事务管理

    ·可选择的配置有SqlSessionTemplate

    配置数据源:

    xml方式:

    <!-- 数据库连接池 -->
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />
            <property name="url" value="jdbc:mysql://localhost:3306/role?characterEncoding=utf-8&amp;useSSL=false&amp;serverTimezone=GMT%2B8&amp;allowPublicKeyRetrieval=true"/>
            <property name="username" value="root" />
            <property name="password" value="123456abc" />
            <property name="maxActive" value="255" />
            <property name="maxIdle" value="5" />
            <property name="maxWait" value="10000" />
        </bean>

    config类配置:

    /**
         * 配置数据库
         * @return 数据库连接池
         */
        @Bean(name="dataSource")
        public DataSource initDataSource() {
            if(dataSource!=null) {
                return dataSource;
            }
            Properties props=new Properties();
            props.setProperty("driverClassName", "com.mysql.cj.jdbc.Driver");
            props.setProperty("url","jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true");
            props.setProperty("userName","root");
            props.setProperty("password","123456abc");
            props.setProperty("maxActive","20");
            props.setProperty("maxIdle","20");
            props.setProperty("maxWait","30000");
            try {
                dataSource=BasicDataSourceFactory.createDataSource(props);
            }catch(Exception e) {
                e.printStackTrace();
            }
            return dataSource;
  • 相关阅读:
    快速入门系列--MVC--05行为
    2015链家网面试记录
    快速入门系列--MVC--04模型
    django 添加动态表格的方法
    git clone
    postgresql数据库实用操作
    django 实战
    Android手机分辨率基础知识(DPI,DIP计算)
    Android中xml设置Animation动画效果详解
    Unable to execute dex: Multiple dex files define Lcom/gl
  • 原文地址:https://www.cnblogs.com/xc-xinxue/p/12482190.html
Copyright © 2011-2022 走看看