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 ...
随机推荐
- vue history模式下的微信分享
// 微信验证 export function requireConfig() { let url = window.location.href systemApi.wxoption({ url: u ...
- CentOS源码编译安装MySQL 5.5.15
CentOS源码编译安装MySQL 5.5.15 文章目录 [隐藏] 安装编译工具 下载源码 安装cmake和bison 编译安装MySQL 一些相关设置 安装编译工具 yum install g ...
- mysql数据库密码
一. oOO6jpspg/j5 二. alter user root@localhost IDENTIFIED BY '123'; 三. create database s11Madking char ...
- WinServer2008R2远程桌面长时间保持连接
开始------运行------gpedit.msc 计算机配置------管理模板-----Windows组件-----远程桌面服务------远程桌面会话主机------会话时间限制 修改两项设置 ...
- ForkJoinPool及并行流解析
parallelStream原理. parallelStream是并行流,依赖jdk1.7出现的Fork/Join框架. Fork/Join框架的核心是工作窃取(work-stealing)算法.那么 ...
- grpc:gRPC Concepts
本文介绍一些主要的gRPC概念. 服务定义 gRPC支持4种方法: 1.Unary RPCs where the client sends a single request to the server ...
- spring自带工具类
在spring-core.jar包中,org.springframework.util package下有很多工具类,这些工具类十分具有参考意义.
- long poll、ajax轮询和WebSocket
websocket 的认识深刻有木有.所以转到我博客里,分享一下.比较喜欢看这种博客,读起来很轻松,不枯燥,没有布道师的阵仗,纯粹为分享.废话这么多了,最后再赞一个~ WebSocket是出的东西(协 ...
- 第十周java学习总结
目录 第十周java学习总结 学习内容 代码上传截图 代码链接 第十周java学习总结 学习内容 第12章 Java多线程机制 主要内容 Java中的线程 Thread类与线程的创建 线程的常用方法 ...
- vue中下载excel的使用,后端链接两种情况,一个是链接,一个是文件流
vue中下载excel使用 一.这是第一种情况,后台链接地址返回的是一个url,这个时候我只要在导出按钮上绑定exportData()这个事件方法就好了 exportData() { this ...