springboot + mybaits + oracle 项目
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 >= 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安装
链接:https://pan.baidu.com/s/1OgKUmExGfxIfMV1yUqFHOw
提取码:f3uy
springboot + mybaits + oracle 项目的更多相关文章
- springboot + mybatis 的项目,实现简单的CRUD
以前都是用Springboot+jdbcTemplate实现CRUD 但是趋势是用mybatis,今天稍微修改,创建springboot + mybatis 的项目,实现简单的CRUD 上图是项目的 ...
- springboot引入Oracle依赖
最近学习spring boot,在网上找一些项目学习,有的项目引入了oracle驱动包,自己搭建一直不成功,百度发现说是权限问题无法下载. 然后参考下面博客终于解决:springboot引入Oracl ...
- spring-boot 多模块化项目和EurekaServer的搭建
Spring boot由于其 1.易于开发和维护.2.单个微服务启动快.3.局部修改部署容易.4.技术栈不受语言限制等优点受到越来越多公司的重视.spring-boot还集成了许多关于微服务开发的框架 ...
- SpringBoot多模块项目打包问题
项目结构图如下: 在SpringBoot多模块项目打包时遇见如下错误: 1.repackage failed: Unable to find main class -> [Help 1] 解决步 ...
- springBoot 搭建web项目(前后端分离,附项目源代码地址)
springBoot 搭建web项目(前后端分离,附项目源代码地址) 概述 该项目包含springBoot-example-ui 和 springBoot-example,分别为前端与后端,前后端 ...
- 使用SpringBoot整合ssm项目
SpringBoot是什么? Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程. Spring Boot 现在已经成为Java ...
- 2017-09-26 发布 SpringBoot多模块项目实践(Multi-Module)
https://segmentfault.com/a/1190000011367492?utm_source=tag-newest 2017-09-26 发布 SpringBoot多模块项目实践(Mu ...
- springboot搭建web项目(转)
转:http://blog.csdn.net/linzhiqiang0316/article/details/52589789 这几天一直在研究IDEA上面怎么搭建一个web-mvc的SpringBo ...
- eclipse中SpringBoot的maven项目出现无法解析父类的解决办法
在eclipse中建立SpringBoot的maven项目时,继承父类,添加如下代码: <parent> <groupId>org.springframework.boot&l ...
随机推荐
- Git之协同开发
Github之协同开发 一.协同开发 1.引子:假如三个人共同开发同一份代码,每个人都各自安排了任务,当每个人都完成了一半的时候,提交不提交呢? 要提交,提交到dev吗,都上传了一半,这样回家拿出来的 ...
- 玩蛇记之用python实现易宝快速支付接口
玩蛇记之用python实现易宝快速支付接口 现在很多这种快速支付的通道,易宝支持的通道算是很全面的,正好最近需要集成易宝的支付通道到平台中,所以写一贴来记录一下,顺便鄙视一下国内的支付平台,api的支 ...
- 那些jquery或javascript花招
js定时器 定时器: 1)反复性定时器:格式:window.setInterval(“fn()”,1000); a)会反复执行 b)第二个参数是以毫秒计算的 2)一次性定时器:格式:window.se ...
- 【JZOJ1282】打工
题目 分析 显然,有一个结论, 在有效的方案中,第i位的数一定小于等于i. 所以,设\(f_{i,j,k}\)表示,做到第i位,前i位的最大值为j,前i位是否与输入的序列的前i位相等. 转移方程随便搞 ...
- chrome scrollTop 获取失败问题及解决方案
https://blog.csdn.net/h357650113/article/details/78384621
- app自动化的执行
appium --address 127.0.0.1 --port 10000 --bootstrap-port 10100 --webdriveragent-port 10110 在指定的目录下执行 ...
- Shell-06 函数
Shell-06 函数 #编写脚本,使用chkconfig命令,循环执行,关闭所有5级别服务 #!/bin/bash name=`chkconfig --list | cut -d' ' -f1` f ...
- MySQL 运维管理平台
github: https://github.com/XiaohaoYu/mysql_platform
- json 转xml
var jStr = JsonConvert.SerializeObject(new { root = new { li = list } }); var xml = JsonConvert.Dese ...
- Linux基础教程 linux下cat 命令使用详解
cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1.命令格式: cat [选项] [文件] ...