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;
  • 相关阅读:
    Linux Command
    sql查询将列里面的值替换为别的值但是实际值不变
    MY_SQLCode
    ComboBox设置Text属性
    WPF bmp和二进制转换
    C#中打开文件、目录、保存窗口
    WPF实现右键菜单
    BarTender SDK 实现调用模板条码打印
    VS Code非英语版本连接TFS错误解决方案
    DBeaver连接达梦数据库
  • 原文地址:https://www.cnblogs.com/xc-xinxue/p/12482190.html
Copyright © 2011-2022 走看看