1.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>com.itstudy</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version> <name>demo</name>
<description>demo</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<!-- <version>1.0.0</version>-->
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- 链接oracle 11 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.1.0.7.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.30</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

2.src/main/resources/application.properties

server.port=9101
server.display-name=
server.name=conduct-rules-ranking spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
#设置数据库链接
#spring.datasource.url=jdbc:oracle:thin:@192.168.150.63:1521:ufnc
spring.datasource.url=jdbc:oracle:thin:@192.168.150.63:1521/ufnc
spring.datasource.username=syxwexam
spring.datasource.password=am67#bcm1 #配置映射路径
mybatis.mapperLocations=classpath:mapper/*.xml
#打印sql语句
logging.level.com.itstudy.demo.dao=debug

3.src/main/resources/mapper/RankingMapper.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.itstudy.demo.dao.RankingMapper">
<resultMap id="BaseResultMap" type="com.itstudy.demo.domain.RankingInfo">
<result property="zuzhixz" column="zuzhixz"/>
<result property="zuzhifl" column="zuzhifl"/>
<result property="zongshu" column="zongshu"/>
<result property="yikaoshi" column="yikaoshi"/>
<result property="bilv" column="bilv"/>
</resultMap>
<select id="findRankingAll" resultMap="BaseResultMap"> with s1 as (
select zuzhixz,zuzhifl,count(*) as zongshu from view_active_business
where unitname not like '%分公司%' and unitname not like '%事业部%'
group by zuzhifl,zuzhixz ),
s2 as (select zuzhixz,zuzhifl,count(*) as yikaoshi from view_active_business
where (unitname not like '%分公司%' and unitname not like '%事业部%') and zt ='正常'
group by zuzhifl,zuzhixz ) select a.zuzhixz,a.zuzhifl,a.zongshu,nvl(b.yikaoshi,0) as yikaoshi,to_char(nvl(b.yikaoshi,0)/nvl(a.zongshu,1),'FM0.0000') as bilv from s1 a left join s2 b on a.zuzhifl = b.zuzhifl where a.zongshu &gt;= 30 </select>
</mapper>

3. src/main/java/com/itstudy/demo/dao/RankingMapper.java

package com.itstudy.demo.dao;

import com.itstudy.demo.domain.RankingInfo;
import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper
public interface RankingMapper { List<RankingInfo> findRankingAll();
}

4. src/main/java/com/itstudy/demo/domain/RankingInfo.java

package com.itstudy.demo.domain;

/**
* 排序信息
*/
public class RankingInfo { private String zuzhixz;
private String zuzhifl; //组织分类
private String zongshu; //总人数
private String yikaoshi; //已考试人数
private String bilv; //比率 public String getZuzhifl() {
return zuzhifl;
} public void setZuzhifl(String zuzhifl) {
this.zuzhifl = zuzhifl;
} public String getZongshu() {
return zongshu;
} public void setZongshu(String zongshu) {
this.zongshu = zongshu;
} public String getYikaoshi() {
return yikaoshi;
} public void setYikaoshi(String yikaoshi) {
this.yikaoshi = yikaoshi;
} public String getBilv() {
return bilv;
} public void setBilv(String bilv) {
this.bilv = bilv;
} public String getZuzhixz() {
return zuzhixz;
} public void setZuzhixz(String zuzhixz) {
this.zuzhixz = zuzhixz;
}
}

5. src/main/java/com/itstudy/demo/controller/RankingController.java

package com.itstudy.demo.controller;

import com.itstudy.demo.dao.RankingMapper;
import com.itstudy.demo.domain.RankingInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap; @RestController
public class RankingController {
@Autowired
private RankingMapper rankingMapper; private ConcurrentHashMap<String, Object> concurrentHashMap = new ConcurrentHashMap<String, Object>(); private String cache_key = "ranking_data"; @GetMapping("/ranking")
public List<RankingInfo> getUser() { List<RankingInfo> query = null;
if (concurrentHashMap != null && concurrentHashMap.containsKey(cache_key)) {
try {
query = (ArrayList<RankingInfo>) concurrentHashMap.get(cache_key);
} catch (Exception ex) { }
} if (query != null) { System.out.println("缓存数据返回...");
return query;
} System.out.println("数据库查询...");
query = rankingMapper.findRankingAll(); query.sort(new Comparator<RankingInfo>() {
@Override
public int compare(RankingInfo o1, RankingInfo o2) { if (o1.getBilv() == null || o2.getBilv() == null) {
return 0;
} return o2.getBilv().compareToIgnoreCase(o1.getBilv());
}
}); if (concurrentHashMap == null) {
concurrentHashMap = new ConcurrentHashMap<String, Object>();
} concurrentHashMap.put(cache_key, query); return query; } //15分钟更新一次缓存数据
@Scheduled(fixedDelay = 900000)
public void updateCacheData() { List<RankingInfo> query = rankingMapper.findRankingAll(); query.sort(new Comparator<RankingInfo>() {
@Override
public int compare(RankingInfo o1, RankingInfo o2) { if (o1.getBilv() == null || o2.getBilv() == null) {
return 0;
} return o2.getBilv().compareToIgnoreCase(o1.getBilv());
}
}); if (concurrentHashMap == null) {
concurrentHashMap = new ConcurrentHashMap<String, Object>();
} concurrentHashMap.put(cache_key, query); System.out.println("更新缓存...");
}
}

6 src/main/java/com/itstudy/demo/Application.java

package com.itstudy.demo;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling; /**
* 考试排名启动类
*
*/
@SpringBootApplication
@EnableScheduling
public class Application
{
public static void main( String[] args )
{
SpringApplication app = new SpringApplication(Application.class);
//关闭banner
app.setBannerMode(Banner.Mode.OFF);
app.run(args); }
}

7 src/main/java/com/itstudy/demo/CorsConfig.java

package com.itstudy.demo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter; /**
* 实现基本的跨域请求
*
* @author admin
*/
@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 允许任何域名使用
corsConfiguration.addAllowedHeader("*"); // 允许任何头
corsConfiguration.addAllowedMethod("*"); // 允许任何方法(post、get等)
return corsConfiguration;
} @Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", buildConfig()); // 对接口配置跨域设置
return new CorsFilter(source);
}
}

8.重要说明

使用下面的依赖包,要先进行maven安装

<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.1.0.7.0</version>
</dependency>
 
1.下载ojdbc6.jar

链接:https://pan.baidu.com/s/1OgKUmExGfxIfMV1yUqFHOw
提取码:f3uy

2. maven安装命令
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.1.0.7.0 -Dpackaging=jar -Dfile=C:\Users\Administrator\Desktop\11.1.0.7.0\ojdbc6-11.1.0.7.0.jar 
 
 

springboot + mybaits + oracle 项目的更多相关文章

  1. springboot + mybatis 的项目,实现简单的CRUD

    以前都是用Springboot+jdbcTemplate实现CRUD 但是趋势是用mybatis,今天稍微修改,创建springboot + mybatis 的项目,实现简单的CRUD  上图是项目的 ...

  2. springboot引入Oracle依赖

    最近学习spring boot,在网上找一些项目学习,有的项目引入了oracle驱动包,自己搭建一直不成功,百度发现说是权限问题无法下载. 然后参考下面博客终于解决:springboot引入Oracl ...

  3. spring-boot 多模块化项目和EurekaServer的搭建

    Spring boot由于其 1.易于开发和维护.2.单个微服务启动快.3.局部修改部署容易.4.技术栈不受语言限制等优点受到越来越多公司的重视.spring-boot还集成了许多关于微服务开发的框架 ...

  4. SpringBoot多模块项目打包问题

    项目结构图如下: 在SpringBoot多模块项目打包时遇见如下错误: 1.repackage failed: Unable to find main class -> [Help 1] 解决步 ...

  5. springBoot 搭建web项目(前后端分离,附项目源代码地址)

    springBoot 搭建web项目(前后端分离,附项目源代码地址)   概述 该项目包含springBoot-example-ui 和 springBoot-example,分别为前端与后端,前后端 ...

  6. 使用SpringBoot整合ssm项目

    SpringBoot是什么? Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程. Spring Boot 现在已经成为Java ...

  7. 2017-09-26 发布 SpringBoot多模块项目实践(Multi-Module)

    https://segmentfault.com/a/1190000011367492?utm_source=tag-newest 2017-09-26 发布 SpringBoot多模块项目实践(Mu ...

  8. springboot搭建web项目(转)

    转:http://blog.csdn.net/linzhiqiang0316/article/details/52589789 这几天一直在研究IDEA上面怎么搭建一个web-mvc的SpringBo ...

  9. eclipse中SpringBoot的maven项目出现无法解析父类的解决办法

    在eclipse中建立SpringBoot的maven项目时,继承父类,添加如下代码: <parent> <groupId>org.springframework.boot&l ...

随机推荐

  1. SpringMVC @CookieValue注解

    @CookieValue的作用 用来获取Cookie中的值 @CookieValue参数 1.value:参数名称 2.required:是否必须 3.defaultValue:默认值 @Cookie ...

  2. 使用vux的x-input组件中show-clear=“true”清除icon点击失效的问题

    问题场景: 在电脑浏览器点击清除icon正常 在手机浏览器,手机微信,微信开发者工具中点击清除icon失效 查看vux中的x-input组件中的源码发现,清除icon使用了v-show显示与隐藏,对应 ...

  3. Django初使用

    目录 一.Django初使用 1. 静态文件配置 (1)静态文件配置步骤 2. form表单的get和post提交方式 (1)get (2)post (3)注意 3. views文件中的request ...

  4. Leaflet使用vector tiles 标注label设置

    JS //简单的标注 var marker = L.marker([ 31.2, 114.5 ], { // icon:myIcon }).addTo(map) // 设置label .bindToo ...

  5. 这里面ID为002和005的记录是重复的,在这里要把其中一条去掉,达到下面的效果:

    --去掉重复的记录 select ID,Code,ColorNum from (     SELECT      ROW_NUMBER() OVER(         PARTITION BY Cod ...

  6. html b标签 语法

    html b标签 语法 标签b是什么意思? b的意思是bold,b标签主要用于html中规定粗体文本,该标签内的字符将被设为粗体.B标签所传达的意思只是加粗,没有任何其它的作用. 作用:规定粗体文本. ...

  7. JS获取URL指定的参数值

    function GetUrlValue(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)( ...

  8. CVPR 2018 DeepGlobe

    在刚刚结束的CVPR2018: DeepGlobe Road Extraction Challenge(全球卫星图像道路提取)比赛中,北京邮电大学信息与通信工程学院模式识别实验室张闯老师指导的研究生周 ...

  9. 02-scrapy的cmdline命令

    1.启动爬虫的命令为: scrapy crawl spidername(爬虫名) 2.我们还可以通过下述方式来启动爬虫 步骤一:创建一个.py文件.startspider.py(这里文件的名称可以自己 ...

  10. 在windows窗口下打开文件夹

    System.Diagnostics.Process.Start("Explorer.exe", @"C:\Users\gnt-wangt\Documents\Visua ...