zoukankan      html  css  js  c++  java
  • 基本项目框架搭建 sqlserver druid配置

      1.  我的连接池采用的是阿里云的druid的连接池,工具是IDEA 框架是springboot+maven

       以下是我的项目框架结构

     

     2. pom  中配置

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>cn.xudy.sqlservice</groupId>
        <artifactId>StorageSqlService</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.4.RELEASE</version>
            <relativePath/>
        </parent>
    
        <dependencies>
    
    
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.0.25</version>
            </dependency>
            <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>sqljdbc4</artifactId>
                <version>4.0</version>
            </dependency>
            <!-- Spring Boot JDBC -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
    
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
        </dependencies>
    
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    
    </project>

    2. .properties 配置

    server.port=8011
    
    druid.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
    
    
    druid.url=jdbc:sqlserver://localhost:1433;DatabaseName=test
    druid.username=sa
    druid.password=123456

     3. SystemConfig 配置

    package cn.xudy.group.config;
    
    
    
    
    import com.alibaba.druid.pool.DruidDataSource;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Primary;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.stereotype.Component;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    import javax.sql.DataSource;
    
    /**
     * Created by Ulegal on 2017/8/19.
     */
    @Configuration
    public class SystemConfig {
    
    
                @Bean(name = "dataSource")
                @Qualifier(value = "dataSource")
                @Primary
                @ConfigurationProperties(prefix = "druid")
                public DataSource dataSource() {
                    return DataSourceBuilder.create().type(DruidDataSource.class).build();
    
                }
    
    
        /**
         * 跨域
         * @return
         */
        @Bean
        public WebMvcConfigurer corsConfigurer() {
            return new WebMvcConfigurerAdapter() {
                @Override
                public void addCorsMappings(CorsRegistry registry) {
                    registry.addMapping("/**");
                }
            };
        }
    
    }

    4. dao数据层测试

    @Repository
    public class StorageDaoImpl implements StorageDao{
    
        @Autowired
        JdbcTemplate jdbcTemplate;
    
        @Override
        public List<Map<String, Object>> getInfo() {
    
    
            // 传统方法
            List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
            String  sql  =   "SELECT * FROM " + "Table_1" +";";
            list = jdbcTemplate.queryForList(sql);
            System.out.println("-------------"+list);
    
            return list;
        }

       搞定

  • 相关阅读:
    【前端优化之拆分CSS】前端三剑客的分分合合
    ipad&mobile通用webapp框架前哨战
    如何判断一个DOM元素正在动画,一个CSS“阻塞”JS的例子
    关于前端框架升级与全站样式替换的简单建议
    【HTML5&CSS3进阶04】CSS3动画应该如何在webapp中运用
    【HTML5&CSS3进阶03】Jser与Csser如何一起愉快的翻新老组件
    【HTML5&CSS3进阶学习02】Header的实现·CSS中的布局
    【HTML5&CSS3进阶学习01】气泡组件的实现
    【模块化编程】理解requireJS-实现一个简单的模块加载器
    【小贴士】探一探javascript中的replace
  • 原文地址:https://www.cnblogs.com/memoryXudy/p/7767741.html
Copyright © 2011-2022 走看看