DRUID配置多資料來源專案
阿新 • • 發佈:2019-02-09
/** * @Title: DruidStatViewServlet.java * @Package org.spring.springboot.servlet * @Description: TODO(用一句話描述該檔案做什麼) * @author pengfei * @date 2017年7月15日 下午3:28:13 * @version V1.0 */ package org.spring.springboot.servlet; import javax.servlet.annotation.WebInitParam; import javax.servlet.annotation.WebServlet; import com.alibaba.druid.support.http.StatViewServlet; /** * StatViewServlet * * @author 單紅宇(365384722) * @myblog http://blog.csdn.net/catoop/ * @create 2016年3月17日 */ @SuppressWarnings("serial") @WebServlet(urlPatterns = "/druid/*", initParams={ @WebInitParam(name="allow",value="192.168.16.110,127.0.0.1"),// IP白名單 (沒有配置或者為空,則允許所有訪問) @WebInitParam(name="deny",value="192.168.16.111"),// IP黑名單 (存在共同時,deny優先於allow) @WebInitParam(name="loginUsername",value="admin"),// 使用者名稱 @WebInitParam(name="loginPassword",value="123456"),// 密碼 @WebInitParam(name="resetEnable",value="false")// 禁用HTML頁面上的“Reset All”功能 }) public class DruidStatViewServlet extends StatViewServlet{ }
關於DRUID配置多資料來源相信您在網上也找到不少文章,每個人方法各有不同,供大道同歸,原理都是一樣的;
介紹:
Druid是阿里巴巴開源平臺上的一個專案,整個專案由資料庫連線池、外掛框架和SQL解析器組成。該專案主要是為了擴充套件JDBC的一些限制,可以讓程式設計師實現一些特殊的需求,比如向金鑰服務請求憑證、統計SQL資訊、SQL效能收集、SQL注入檢查、SQL翻譯等,程式設計師可以通過定製來實現自己需要的功能。
個人理解:主要實現了資料來源的優化,和對SQL的監控功能,對事務的管理還是解決JDBC 或 JTA那套來管理事務,我還是參照網上的JDBC事務。
我主要採用spring boot+druid配置資料來源,包括事務的管理。
這是我對新技術採用的方法,應該可以放大圖片來看:
圖上鍊接我給大家發下,也有可能會失效,因為隨網站內容變更啊
同類技術對比:https://github.com/alibaba/druid/wiki/%E5%90%84%E7%A7%8D%E8%BF%9E%E6%8E%A5%E6%B1%A0%E6%80%A7%E8%83%BD%E5%AF%B9%E6%AF%94%E6%B5%8B%E8%AF%95
官方示例:http://www.iteye.com/magazines/90#123 只是管理了連結池
文件:https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter
看開原始碼:https://github.com/AlibabaTech/druid
我直接寫配置方法了:
application.properties
## master 資料來源配置
master.datasource.url=jdbc:oracle:thin:@10.20.100.193:1521:mestest1
master.datasource.username=qnmest1
master.datasource.password=qnmest1
master.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
## cluster 資料來源配置
cluster.datasource.url=jdbc:mysql://localhost:3306/springbootdb_cluster?useUnicode=true&characterEncoding=utf8
cluster.datasource.username=root
cluster.datasource.password=root
cluster.datasource.driverClassName=com.mysql.jdbc.Driver
# 下面為連線池的補充設定,應用到上面所有資料來源中
# 初始化大小,最小,最大
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
# 配置獲取連線等待超時的時間
spring.datasource.maxWait=60000
# 配置間隔多久才進行一次檢測,檢測需要關閉的空閒連線,單位是毫秒
spring.datasource.timeBetweenEvictionRunsMillis=60000
# 配置一個連線在池中最小生存的時間,單位是毫秒
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.logImpl=STDOUT_LOGGING
# 開啟PSCache,並且指定每個連線上PSCache的大小
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# 配置監控統計攔截的filters,去掉後監控介面sql無法統計,'wall'用於防火牆
spring.datasource.filters=stat,wall,log4j
# 通過connectProperties屬性來開啟mergeSql功能;慢SQL記錄
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合併多個DruidDataSource的監控資料
spring.datasource.useGlobalDataSourceStat=true
logback.access.config.path=./src/main/respirces/logback.xml
MasterDataSourceConfig
package org.spring.springboot.config.ds;
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
@Configuration
// 掃描 Mapper 介面並容器管理
@MapperScan(basePackages = MasterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory")
public class MasterDataSourceConfig {
// 精確到 master 目錄,以便跟其他資料來源隔離
static final String PACKAGE = "org.spring.springboot.dao.master";
static final String MAPPER_LOCATION = "classpath:mapper/master/*.xml";
@Value("${master.datasource.url}")
private String url;
@Value("${master.datasource.username}")
private String user;
@Value("${master.datasource.password}")
private String password;
@Value("${master.datasource.driverClassName}")
private String driverClass;
@Bean(name = "masterDataSource")
@Primary
public DataSource masterDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(user);
dataSource.setPassword(password);
return dataSource;
}
@Bean(name = "masterTransactionManager")
@Primary
public DataSourceTransactionManager masterTransactionManager() {
return new DataSourceTransactionManager(masterDataSource());
}
@Bean(name = "masterSqlSessionFactory")
@Primary
public SqlSessionFactory masterSqlSessionFactory(@Qualifier("masterDataSource") DataSource masterDataSource)
throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(masterDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(MasterDataSourceConfig.MAPPER_LOCATION));
return sessionFactory.getObject();
}
}
ClusterDataSourceConfig
package org.spring.springboot.config.ds;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import com.alibaba.druid.pool.DruidDataSource;
@Configuration
// 掃描 Mapper 介面並容器管理
@MapperScan(basePackages = ClusterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "clusterSqlSessionFactory")
public class ClusterDataSourceConfig {
// 精確到 cluster 目錄,以便跟其他資料來源隔離
static final String PACKAGE = "org.spring.springboot.dao.cluster";
static final String MAPPER_LOCATION = "classpath:mapper/cluster/*.xml";
@Value("${cluster.datasource.url}")
private String url;
@Value("${cluster.datasource.username}")
private String user;
@Value("${cluster.datasource.password}")
private String password;
@Value("${cluster.datasource.driverClassName}")
private String driverClass;
@Bean(name = "clusterDataSource")
public DataSource clusterDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driverClass);
dataSource.setUrl(url);
dataSource.setUsername(user);
dataSource.setPassword(password);
return dataSource;
}
@Bean(name = "clusterTransactionManager") //這裡就是事務控制了
public DataSourceTransactionManager clusterTransactionManager() {
return new DataSourceTransactionManager(clusterDataSource());
}
@Bean(name = "clusterSqlSessionFactory")
public SqlSessionFactory clusterSqlSessionFactory(@Qualifier("clusterDataSource") DataSource clusterDataSource)
throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(clusterDataSource);
sessionFactory.setMapperLocations(
new PathMatchingResourcePatternResolver().getResources(ClusterDataSourceConfig.MAPPER_LOCATION));
return sessionFactory.getObject();
}
}
IntfCalculateZpfMapper
package org.spring.springboot.dao.master;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.spring.springboot.domain.IntfCalculateZpf;
public interface IntfCalculateZpfMapper {
int deleteByPrimaryKey(Date sysid);
int insert(IntfCalculateZpf record);
int insertSelective(IntfCalculateZpf record);
IntfCalculateZpf selectByPrimaryKey(Date sysid);
List<IntfCalculateZpf> selectBySid(BigDecimal sid);
int updateByPrimaryKeySelective(IntfCalculateZpf record);
int updateByPrimaryKey(IntfCalculateZpf record);
}
IntfCalculateZpfMapper.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="org.spring.springboot.dao.master.IntfCalculateZpfMapper" >
<resultMap id="BaseResultMap" type="org.spring.springboot.domain.IntfCalculateZpf" >
<constructor >
<idArg column="SYSID" jdbcType="TIMESTAMP" javaType="java.util.Date" />
<arg column="SID" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
<arg column="APPLY_ID" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="CAR_NO" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="L4_MATNR" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="MAT_NAME" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="PRICE_UNIT" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="GROSS_WT" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
<arg column="GROSS_DATE" jdbcType="TIMESTAMP" javaType="java.util.Date" />
<arg column="TARE_WT" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
<arg column="TARE_DATE" jdbcType="TIMESTAMP" javaType="java.util.Date" />
<arg column="WEIGHT" jdbcType="DECIMAL" javaType="java.math.BigDecimal" />
<arg column="WT_UNIT" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="GROSS_BY" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="BUSINESS_ID" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="BUSINESS_TYPE" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="APPLY_ID_L2" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="SUPPLY_NAME" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="GROSS_DATE_2" jdbcType="TIMESTAMP" javaType="java.util.Date" />
<arg column="GROSS_DATE_1" jdbcType="TIMESTAMP" javaType="java.util.Date" />
<arg column="GROSS_STATION_1" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="LADLE_SEQ" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="CELL_ID_LIST" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="ASSIGNMENT" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="UNIT_CARRIED_NAME" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="REMARK" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="FLAG" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="LADLE_ID" jdbcType="VARCHAR" javaType="java.lang.String" />
</constructor>
</resultMap>
<sql id="Base_Column_List" >
SYSID, SID, APPLY_ID, CAR_NO, L4_MATNR, MAT_NAME, PRICE_UNIT, GROSS_WT, GROSS_DATE,
TARE_WT, TARE_DATE, WEIGHT, WT_UNIT, GROSS_BY, BUSINESS_ID, BUSINESS_TYPE, APPLY_ID_L2,
SUPPLY_NAME, GROSS_DATE_2, GROSS_DATE_1, GROSS_STATION_1, LADLE_SEQ, CELL_ID_LIST,
ASSIGNMENT, UNIT_CARRIED_NAME, REMARK, FLAG, LADLE_ID
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.util.Date" >
select
<include refid="Base_Column_List" />
from INTF_CALCULATE_ZPF
where SYSID = #{sysid,jdbcType=TIMESTAMP}
</select>
<select id="selectBySid" resultMap="BaseResultMap" parameterType="java.math.BigDecimal" >
select
<include refid="Base_Column_List" />
from INTF_CALCULATE_ZPF
where SID = #{sid,jdbcType=DECIMAL}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.util.Date" >
delete from INTF_CALCULATE_ZPF
where SYSID = #{sysid,jdbcType=TIMESTAMP}
</delete>
<insert id="insert" parameterType="org.spring.springboot.domain.IntfCalculateZpf" >
insert into INTF_CALCULATE_ZPF (SYSID, SID, APPLY_ID,
CAR_NO, L4_MATNR, MAT_NAME,
PRICE_UNIT, GROSS_WT, GROSS_DATE,
TARE_WT, TARE_DATE, WEIGHT,
WT_UNIT, GROSS_BY, BUSINESS_ID,
BUSINESS_TYPE, APPLY_ID_L2, SUPPLY_NAME,
GROSS_DATE_2, GROSS_DATE_1, GROSS_STATION_1,
LADLE_SEQ, CELL_ID_LIST, ASSIGNMENT,
UNIT_CARRIED_NAME, REMARK, FLAG,
LADLE_ID)
values (#{sysid,jdbcType=TIMESTAMP}, #{sid,jdbcType=DECIMAL}, #{applyId,jdbcType=VARCHAR},
#{carNo,jdbcType=VARCHAR}, #{l4Matnr,jdbcType=VARCHAR}, #{matName,jdbcType=VARCHAR},
#{priceUnit,jdbcType=VARCHAR}, #{grossWt,jdbcType=DECIMAL}, #{grossDate,jdbcType=TIMESTAMP},
#{tareWt,jdbcType=DECIMAL}, #{tareDate,jdbcType=TIMESTAMP}, #{weight,jdbcType=DECIMAL},
#{wtUnit,jdbcType=VARCHAR}, #{grossBy,jdbcType=VARCHAR}, #{businessId,jdbcType=VARCHAR},
#{businessType,jdbcType=VARCHAR}, #{applyIdL2,jdbcType=VARCHAR}, #{supplyName,jdbcType=VARCHAR},
#{grossDate2,jdbcType=TIMESTAMP}, #{grossDate1,jdbcType=TIMESTAMP}, #{grossStation1,jdbcType=VARCHAR},
#{ladleSeq,jdbcType=VARCHAR}, #{cellIdList,jdbcType=VARCHAR}, #{assignment,jdbcType=VARCHAR},
#{unitCarriedName,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{flag,jdbcType=VARCHAR},
#{ladleId,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="org.spring.springboot.domain.IntfCalculateZpf" >
insert into INTF_CALCULATE_ZPF
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="sysid != null" >
SYSID,
</if>
<if test="sid != null" >
SID,
</if>
<if test="applyId != null" >
APPLY_ID,
</if>
<if test="carNo != null" >
CAR_NO,
</if>
<if test="l4Matnr != null" >
L4_MATNR,
</if>
<if test="matName != null" >
MAT_NAME,
</if>
<if test="priceUnit != null" >
PRICE_UNIT,
</if>
<if test="grossWt != null" >
GROSS_WT,
</if>
<if test="grossDate != null" >
GROSS_DATE,
</if>
<if test="tareWt != null" >
TARE_WT,
</if>
<if test="tareDate != null" >
TARE_DATE,
</if>
<if test="weight != null" >
WEIGHT,
</if>
<if test="wtUnit != null" >
WT_UNIT,
</if>
<if test="grossBy != null" >
GROSS_BY,
</if>
<if test="businessId != null" >
BUSINESS_ID,
</if>
<if test="businessType != null" >
BUSINESS_TYPE,
</if>
<if test="applyIdL2 != null" >
APPLY_ID_L2,
</if>
<if test="supplyName != null" >
SUPPLY_NAME,
</if>
<if test="grossDate2 != null" >
GROSS_DATE_2,
</if>
<if test="grossDate1 != null" >
GROSS_DATE_1,
</if>
<if test="grossStation1 != null" >
GROSS_STATION_1,
</if>
<if test="ladleSeq != null" >
LADLE_SEQ,
</if>
<if test="cellIdList != null" >
CELL_ID_LIST,
</if>
<if test="assignment != null" >
ASSIGNMENT,
</if>
<if test="unitCarriedName != null" >
UNIT_CARRIED_NAME,
</if>
<if test="remark != null" >
REMARK,
</if>
<if test="flag != null" >
FLAG,
</if>
<if test="ladleId != null" >
LADLE_ID,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="sysid != null" >
#{sysid,jdbcType=TIMESTAMP},
</if>
<if test="sid != null" >
#{sid,jdbcType=DECIMAL},
</if>
<if test="applyId != null" >
#{applyId,jdbcType=VARCHAR},
</if>
<if test="carNo != null" >
#{carNo,jdbcType=VARCHAR},
</if>
<if test="l4Matnr != null" >
#{l4Matnr,jdbcType=VARCHAR},
</if>
<if test="matName != null" >
#{matName,jdbcType=VARCHAR},
</if>
<if test="priceUnit != null" >
#{priceUnit,jdbcType=VARCHAR},
</if>
<if test="grossWt != null" >
#{grossWt,jdbcType=DECIMAL},
</if>
<if test="grossDate != null" >
#{grossDate,jdbcType=TIMESTAMP},
</if>
<if test="tareWt != null" >
#{tareWt,jdbcType=DECIMAL},
</if>
<if test="tareDate != null" >
#{tareDate,jdbcType=TIMESTAMP},
</if>
<if test="weight != null" >
#{weight,jdbcType=DECIMAL},
</if>
<if test="wtUnit != null" >
#{wtUnit,jdbcType=VARCHAR},
</if>
<if test="grossBy != null" >
#{grossBy,jdbcType=VARCHAR},
</if>
<if test="businessId != null" >
#{businessId,jdbcType=VARCHAR},
</if>
<if test="businessType != null" >
#{businessType,jdbcType=VARCHAR},
</if>
<if test="applyIdL2 != null" >
#{applyIdL2,jdbcType=VARCHAR},
</if>
<if test="supplyName != null" >
#{supplyName,jdbcType=VARCHAR},
</if>
<if test="grossDate2 != null" >
#{grossDate2,jdbcType=TIMESTAMP},
</if>
<if test="grossDate1 != null" >
#{grossDate1,jdbcType=TIMESTAMP},
</if>
<if test="grossStation1 != null" >
#{grossStation1,jdbcType=VARCHAR},
</if>
<if test="ladleSeq != null" >
#{ladleSeq,jdbcType=VARCHAR},
</if>
<if test="cellIdList != null" >
#{cellIdList,jdbcType=VARCHAR},
</if>
<if test="assignment != null" >
#{assignment,jdbcType=VARCHAR},
</if>
<if test="unitCarriedName != null" >
#{unitCarriedName,jdbcType=VARCHAR},
</if>
<if test="remark != null" >
#{remark,jdbcType=VARCHAR},
</if>
<if test="flag != null" >
#{flag,jdbcType=VARCHAR},
</if>
<if test="ladleId != null" >
#{ladleId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="org.spring.springboot.domain.IntfCalculateZpf" >
update INTF_CALCULATE_ZPF
<set >
<if test="sid != null" >
SID = #{sid,jdbcType=DECIMAL},
</if>
<if test="applyId != null" >
APPLY_ID = #{applyId,jdbcType=VARCHAR},
</if>
<if test="carNo != null" >
CAR_NO = #{carNo,jdbcType=VARCHAR},
</if>
<if test="l4Matnr != null" >
L4_MATNR = #{l4Matnr,jdbcType=VARCHAR},
</if>
<if test="matName != null" >
MAT_NAME = #{matName,jdbcType=VARCHAR},
</if>
<if test="priceUnit != null" >
PRICE_UNIT = #{priceUnit,jdbcType=VARCHAR},
</if>
<if test="grossWt != null" >
GROSS_WT = #{grossWt,jdbcType=DECIMAL},
</if>
<if test="grossDate != null" >
GROSS_DATE = #{grossDate,jdbcType=TIMESTAMP},
</if>
<if test="tareWt != null" >
TARE_WT = #{tareWt,jdbcType=DECIMAL},
</if>
<if test="tareDate != null" >
TARE_DATE = #{tareDate,jdbcType=TIMESTAMP},
</if>
<if test="weight != null" >
WEIGHT = #{weight,jdbcType=DECIMAL},
</if>
<if test="wtUnit != null" >
WT_UNIT = #{wtUnit,jdbcType=VARCHAR},
</if>
<if test="grossBy != null" >
GROSS_BY = #{grossBy,jdbcType=VARCHAR},
</if>
<if test="businessId != null" >
BUSINESS_ID = #{businessId,jdbcType=VARCHAR},
</if>
<if test="businessType != null" >
BUSINESS_TYPE = #{businessType,jdbcType=VARCHAR},
</if>
<if test="applyIdL2 != null" >
APPLY_ID_L2 = #{applyIdL2,jdbcType=VARCHAR},
</if>
<if test="supplyName != null" >
SUPPLY_NAME = #{supplyName,jdbcType=VARCHAR},
</if>
<if test="grossDate2 != null" >
GROSS_DATE_2 = #{grossDate2,jdbcType=TIMESTAMP},
</if>
<if test="grossDate1 != null" >
GROSS_DATE_1 = #{grossDate1,jdbcType=TIMESTAMP},
</if>
<if test="grossStation1 != null" >
GROSS_STATION_1 = #{grossStation1,jdbcType=VARCHAR},
</if>
<if test="ladleSeq != null" >
LADLE_SEQ = #{ladleSeq,jdbcType=VARCHAR},
</if>
<if test="cellIdList != null" >
CELL_ID_LIST = #{cellIdList,jdbcType=VARCHAR},
</if>
<if test="assignment != null" >
ASSIGNMENT = #{assignment,jdbcType=VARCHAR},
</if>
<if test="unitCarriedName != null" >
UNIT_CARRIED_NAME = #{unitCarriedName,jdbcType=VARCHAR},
</if>
<if test="remark != null" >
REMARK = #{remark,jdbcType=VARCHAR},
</if>
<if test="flag != null" >
FLAG = #{flag,jdbcType=VARCHAR},
</if>
<if test="ladleId != null" >
LADLE_ID = #{ladleId,jdbcType=VARCHAR},
</if>
</set>
where SYSID = #{sysid,jdbcType=TIMESTAMP}
</update>
<update id="updateByPrimaryKey" parameterType="org.spring.springboot.domain.IntfCalculateZpf" >
update INTF_CALCULATE_ZPF
set SID = #{sid,jdbcType=DECIMAL},
APPLY_ID = #{applyId,jdbcType=VARCHAR},
CAR_NO = #{carNo,jdbcType=VARCHAR},
L4_MATNR = #{l4Matnr,jdbcType=VARCHAR},
MAT_NAME = #{matName,jdbcType=VARCHAR},
PRICE_UNIT = #{priceUnit,jdbcType=VARCHAR},
GROSS_WT = #{grossWt,jdbcType=DECIMAL},
GROSS_DATE = #{grossDate,jdbcType=TIMESTAMP},
TARE_WT = #{tareWt,jdbcType=DECIMAL},
TARE_DATE = #{tareDate,jdbcType=TIMESTAMP},
WEIGHT = #{weight,jdbcType=DECIMAL},
WT_UNIT = #{wtUnit,jdbcType=VARCHAR},
GROSS_BY = #{grossBy,jdbcType=VARCHAR},
BUSINESS_ID = #{businessId,jdbcType=VARCHAR},
BUSINESS_TYPE = #{businessType,jdbcType=VARCHAR},
APPLY_ID_L2 = #{applyIdL2,jdbcType=VARCHAR},
SUPPLY_NAME = #{supplyName,jdbcType=VARCHAR},
GROSS_DATE_2 = #{grossDate2,jdbcType=TIMESTAMP},
GROSS_DATE_1 = #{grossDate1,jdbcType=TIMESTAMP},
GROSS_STATION_1 = #{grossStation1,jdbcType=VARCHAR},
LADLE_SEQ = #{ladleSeq,jdbcType=VARCHAR},
CELL_ID_LIST = #{cellIdList,jdbcType=VARCHAR},
ASSIGNMENT = #{assignment,jdbcType=VARCHAR},
UNIT_CARRIED_NAME = #{unitCarriedName,jdbcType=VARCHAR},
REMARK = #{remark,jdbcType=VARCHAR},
FLAG = #{flag,jdbcType=VARCHAR},
LADLE_ID = #{ladleId,jdbcType=VARCHAR}
where SYSID = #{sysid,jdbcType=TIMESTAMP}
</update>
</mapper>
IntfCalculateZpfServiceImpl
/**
* @Title: IntfCalculateZpfServiceImpl.java
* @Package org.spring.springboot.service.impl
* @Description: TODO(用一句話描述該檔案做什麼)
* @author pengfei
* @date 2017年7月15日 上午10:57:54
* @version V1.0
*/
package org.spring.springboot.service.impl;
import java.math.BigDecimal;
import java.util.Date;
import org.spring.springboot.dao.master.IntfCalculateZpfMapper;
import org.spring.springboot.domain.IntfCalculateZpf;
import org.spring.springboot.service.IntfCalculateZpfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author zhangPengFei QQ:635332940
* @version 建立時間:2017年7月15日 上午10:57:54
* 說明 :
*/
/**
* @author pengfei
*@version 建立時間:2017年7月15日 上午10:57:54
* @Description:TODO(這裡用一句話描述這個類的作用)
*
*/
@Service
public class IntfCalculateZpfServiceImpl implements IntfCalculateZpfService {
@Autowired
private IntfCalculateZpfMapper intfCalculateZpfDao; // 主資料來源
/* (非 Javadoc)
* <p>Title: selectBySid</p>
* <p>Description: </p>
* @param sid
* @return
* @see org.spring.springboot.service.IntfCalculateZpfService#selectBySid(java.lang.String)
*/
@Transactional //這個就是事務控制
public IntfCalculateZpf selectBySid(String sid) {
IntfCalculateZpf inf=intfCalculateZpfDao.selectByPrimaryKey(null);
IntfCalculateZpf record=new IntfCalculateZpf();
BigDecimal sid1=new BigDecimal(12);
record.setSid(sid1);
record.setCarNo("FDSAFSFASF");
record.setSysid(new Date());
intfCalculateZpfDao.insert(record);
int a=4/1;
System.out.println(a);
return inf;
}
}
Application
package org.spring.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
/**
* Spring Boot 應用啟動類
*
* Created by bysocket on 16/4/26.
*/
// Spring Boot 應用的標識
@SpringBootApplication
@ServletComponentScan
//@MapperScan 如果Mapper下面沒有@mapper 這個就要加上去,官方說的,但我沒有加也運行了,具體請各位指教
public class Application {
public static void main(String[] args) {
// 程式啟動入口
// 啟動嵌入式的 Tomcat 並初始化 Spring 環境及其各 Spring 元件
SpringApplication.run(Application.class,args);
}
}
DruidStatFilter
/**
* @Title: DruidStatFilter.java
* @Package org.spring.springboot.servlet
* @Description: TODO(用一句話描述該檔案做什麼)
* @author pengfei
* @date 2017年7月15日 下午3:28:56
* @version V1.0
*/
package org.spring.springboot.servlet;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import com.alibaba.druid.support.http.WebStatFilter;
/**
* Druid的StatFilter
*
* @author 單紅宇(365384722)
* @myblog http://blog.csdn.net/catoop/
* @create 2016年3月17日
*/
@WebFilter(filterName="druidWebStatFilter",urlPatterns="/*",
initParams={
@WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略資源
})
public class DruidStatFilter extends WebStatFilter {
}
DruidStatViewServlet
/**
* @Title: DruidStatViewServlet.java
* @Package org.spring.springboot.servlet
* @Description: TODO(用一句話描述該檔案做什麼)
* @author pengfei
* @date 2017年7月15日 下午3:28:13
* @version V1.0
*/
package org.spring.springboot.servlet;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import com.alibaba.druid.support.http.StatViewServlet;
/**
* StatViewServlet
*
* @author 單紅宇(365384722)
* @myblog http://blog.csdn.net/catoop/
* @create 2016年3月17日
*/
@SuppressWarnings("serial")
@WebServlet(urlPatterns = "/druid/*",
initParams={
@WebInitParam(name="allow",value="192.168.16.110,127.0.0.1"),// IP白名單 (沒有配置或者為空,則允許所有訪問)
@WebInitParam(name="deny",value="192.168.16.111"),// IP黑名單 (存在共同時,deny優先於allow)
@WebInitParam(name="loginUsername",value="admin"),// 使用者名稱
@WebInitParam(name="loginPassword",value="123456"),// 密碼
@WebInitParam(name="resetEnable",value="false")// 禁用HTML頁面上的“Reset All”功能
})
public class DruidStatViewServlet extends StatViewServlet{
}
我的測試類:test
/**
* @Title: test.java
* @Package org.test
* @Description: TODO(用一句話描述該檔案做什麼)
* @author pengfei
* @date 2017年7月15日 下午1:03:41
* @version V1.0
*/
package org.test;
import java.math.BigDecimal;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.spring.springboot.Application;
import org.spring.springboot.dao.master.IntfCalculateZpfMapper;
import org.spring.springboot.domain.IntfCalculateZpf;
import org.spring.springboot.service.IntfCalculateZpfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author zhangPengFei QQ:635332940
* @version 建立時間:2017年7月15日 下午1:03:41
* 說明 :
*/
/**
* @author pengfei
*@version 建立時間:2017年7月15日 下午1:03:41
* @Description:TODO(這裡用一句話描述這個類的作用)
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes=Application.class)
public class test {
@Autowired
private IntfCalculateZpfMapper intfCalculateZpfDao; // 主資料來源
@Autowired
private IntfCalculateZpfService intfCalculateZpfService;
@Test
public void test(){
BigDecimal sid=new BigDecimal(12);
List<IntfCalculateZpf> list=intfCalculateZpfDao.selectBySid(sid);
System.out.println(list.size());
}
@Test
public void test2(){
BigDecimal sid=new BigDecimal(12);
IntfCalculateZpf list=intfCalculateZpfService.selectBySid("12");
System.out.println(list);
}
}
基本上就是這樣了,有什麼問題大家可以聯絡我QQ:635332940 張生
下載地址:http://download.csdn.net/detail/zpf5126/9902227