package test.multidatasource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.mifi.service.MifiDeviceService; import com.mifidb.service.SysMifiUserAssetsService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:application*.xml"}) public class MultidatasourceTest { @Autowired MifiDeviceService service1; @Autowired SysMifiUserAssetsService service2; @Test public void Test(){ try{ System.out.println(service1.findAllMifiDevices().get(0).getId()); System.out.println(service2.findAllSysMifiUserAssetses().get(0).getId()); }catch(Exception e){ e.printStackTrace(); } } }
#druid druid.initialSize=5 druid.minIdle=5 druid.maxActive=15 druid.maxWait=6000 druid.timeBetweenEvictionRunsMillis=3000 druid.minEvictableIdleTimeMillis=300000 #jpa jpa.database=org.hibernate.dialect.MySQL5Dialect #mysql jdbc.mysql.database=org.hibernate.dialect.MySQL5Dialect jdbc.mysql.driverClassName=com.mysql.jdbc.Driver #mifi database jdbc.mifi.url=jdbc:mysql://localhost:3306/mifi?useUnicode=true&characterEncoding=utf-8 jdbc.mifi.username=root jdbc.mifi.password=root #mififlow database jdbc.mififlow.url=jdbc:mysql://localhost:3306/mififlow?useUnicode=true&characterEncoding=utf-8 jdbc.mififlow.username=root jdbc.mififlow.password=root #mifidb database jdbc.mififlow.url=jdbc:mysql://localhost:3306/mifidb?useUnicode=true&characterEncoding=utf-8 jdbc.mififlow.username=root jdbc.mififlow.password=root
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.1.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> <context:component-scan base-package="com.mifi" /> <context:component-scan base-package="com.mifidb" /> <context:component-scan base-package="com.mififlow" /> <context:property-placeholder location="classpath:db-config.properties" ignore-unresolvable="true"/> <!--dataSource mifi --> <bean id="dataSourceMifi" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="xaDataSourceClassName" value="com.alibaba.druid.pool.xa.DruidXADataSource" /> <property name="uniqueResourceName" value="mifi" /> <property name="xaProperties"> <props> <prop key="url">jdbc:mysql://localhost:3306/mifi?useUnicode=true&characterEncoding=utf-8</prop> <prop key="username">root</prop> <prop key="password">root</prop> </props> </property> </bean> <!--dataSource mififlow --> <bean id="dataSourceMifiFlow" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="xaDataSourceClassName" value="com.alibaba.druid.pool.xa.DruidXADataSource" /> <property name="uniqueResourceName" value="mififlow" /> <property name="xaProperties"> <props> <prop key="url">jdbc:mysql://localhost:3306/mifi_flow?useUnicode=true&characterEncoding=utf-8</prop> <prop key="username">root</prop> <prop key="password">root</prop> </props> </property> </bean> <!--dataSource mifidb --> <bean id="dataSourceMifiDb" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="xaDataSourceClassName" value="com.alibaba.druid.pool.xa.DruidXADataSource" /> <property name="uniqueResourceName" value="mifidb" /> <property name="xaProperties"> <props> <prop key="url">jdbc:mysql://localhost:3306/mifi_db?useUnicode=true&characterEncoding=utf-8</prop> <prop key="username">root</prop> <prop key="password">root</prop> </props> </property> </bean> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.1.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> <!-- mifi --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.mifi.dao" /> <property name="sqlSessionFactory" ref="sqlSessionFactoryMifi"/> </bean> <bean id="sqlSessionFactoryMifi" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSourceMifi"/> <property name="mapperLocations" value="classpath*:com/mifi/mapper/*.xml" /> </bean> <!-- mififlow --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.mififlow.dao" /> <property name="sqlSessionFactory" ref="sqlSessionFactoryMifiFlow"/> </bean> <bean id="sqlSessionFactoryMifiFlow" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSourceMifiFlow"/> <property name="mapperLocations" value="classpath*:com/mififlow/mapper/*.xml" /> </bean> <!-- mifidb --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.mifidb.dao" /> <property name="sqlSessionFactory" ref="sqlSessionFactoryMifiDb"/> </bean> <bean id="sqlSessionFactoryMifiDb" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSourceMifiDb"/> <property name="mapperLocations" value="classpath*:com/mifidb/mapper/*.xml" /> </bean> </beans>
package com.mifi.bean; import java.io.Serializable; import java.sql.Timestamp; public class MifiDevice implements Serializable{ private static final long serialVersionUID = -2696646267915239503L; // id,device_mode,device_type,device_mac,device_no,device_code,device_ip,surplus_flow,create_time,modify_time,status private long id; private String deviceMode; private String deviceType; private String deviceMac; private String deviceNo; private String deviceCode; private String deviceIp; private long surplusFlow; private Timestamp createTime; private Timestamp modifyTime; private int status; public long getId() { return id; } public String getDeviceMode() { return deviceMode; } public String getDeviceType() { return deviceType; } public String getDeviceMac() { return deviceMac; } public String getDeviceNo() { return deviceNo; } public String getDeviceCode() { return deviceCode; } public String getDeviceIp() { return deviceIp; } public long getSurplusFlow() { return surplusFlow; } public Timestamp getCreateTime() { return createTime; } public Timestamp getModifyTime() { return modifyTime; } public int getStatus() { return status; } public void setId(long id) { this.id = id; } public void setDeviceMode(String deviceMode) { this.deviceMode = deviceMode; } public void setDeviceType(String deviceType) { this.deviceType = deviceType; } public void setDeviceMac(String deviceMac) { this.deviceMac = deviceMac; } public void setDeviceNo(String deviceNo) { this.deviceNo = deviceNo; } public void setDeviceCode(String deviceCode) { this.deviceCode = deviceCode; } public void setDeviceIp(String deviceIp) { this.deviceIp = deviceIp; } public void setSurplusFlow(long surplusFlow) { this.surplusFlow = surplusFlow; } public void setCreateTime(Timestamp createTime) { this.createTime = createTime; } public void setModifyTime(Timestamp modifyTime) { this.modifyTime = modifyTime; } public void setStatus(int status) { this.status = status; } }
package com.mifi.dao; import java.util.List; import com.mifi.bean.MifiDevice; public interface MifiDeviceDao { public MifiDevice getMifiDeviceById(long id); public List<MifiDevice> findAllMifiDevices(); public void addMifiDevice(MifiDevice mifiDevice); public void delMifiDeviceById(long id); public void updateMifiDevice(MifiDevice mifiDevice); }
<?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.mifi.dao.MifiDeviceDao"> <!-- id,device_mode,device_type,device_mac,device_no,device_code,device_ip,surplus_flow,create_time,modify_time,status --> <!-- Result Map--> <resultMap type="com.mifi.bean.MifiDevice" id="mifiDevice"> <result property="id" column="id" javaType="long" jdbcType="INTEGER" /> <result property="deviceMode" column="device_mode" javaType="string" jdbcType="VARCHAR"/> <result property="deviceType" column="device_type" javaType="string" jdbcType="VARCHAR"/> <result property="deviceMac" column="device_mac" javaType="string" jdbcType="VARCHAR"/> <result property="deviceNo" column="device_no" javaType="string" jdbcType="VARCHAR" /> <result property="deviceCode" column="device_code" javaType="string" jdbcType="VARCHAR" /> <result property="deviceIp" column="device_ip" javaType="string" jdbcType="VARCHAR" /> <result property="surplusFlow" column="surplus_flow" javaType="long" jdbcType="INTEGER" /> <result property="createTime" column="create_time" jdbcType="TIMESTAMP" javaType="java.sql.Timestamp" /> <result property="modifyTime" column="modify_time" jdbcType="TIMESTAMP" javaType="java.sql.Timestamp" /> <result property="status" column="status" javaType="int" jdbcType="INTEGER" /> </resultMap> <select id="getMifiDeviceById" resultMap="mifiDevice" parameterType="java.lang.Long"> select * from mifi_device where id = #{id,jdbcType=INTEGER} </select> <select id="findAllMifiDevices" resultMap="mifiDevice"> select * from mifi_device </select> <insert id="addMifiDevice" parameterType="com.mifi.bean.MifiDevice"> INSERT INTO mifi_device (id,device_mode,device_type,device_mac,device_no,device_code,device_ip,surplus_flow,create_time,modify_time,status) VALUE (null,#{deviceMode},#{deviceType},#{deviceMac},#{deviceNo},#{deviceCode},#{deviceIp},#{surplusFlow},#{createTime},#{modifyTime},#{status}) </insert> <delete id="delMifiDeviceById" parameterType="java.lang.Long"> delete from mifi_device where id = #{id} </delete> <update id="updateMifiDevice" parameterType="com.mifi.bean.MifiDevice"> update mifi_device <set> <if test="deviceMode != null ">device_mode = #{deviceMode},</if> <if test="deviceType != null ">device_type = #{deviceType},</if> <if test="deviceMac != null ">device_mac = #{deviceMac},</if> <if test="deviceNo != null ">device_no = #{deviceNo},</if> <if test="deviceCode != null ">device_code = #{deviceCode},</if> <if test="deviceIp != null ">device_ip = #{deviceIp},</if> <if test="surplusFlow != null ">surplus_flow = #{surplusFlow,jdbcType=INTEGER},</if> <if test="createTime != null ">create_time = #{createTime,jdbcType=TIMESTAMP},</if> <if test="modifyTime != null ">modify_time = #{modifyTime,jdbcType=TIMESTAMP},</if> <if test="status != null ">status = #{status,jdbcType=INTEGER}</if> </set> where id = #{id,jdbcType=INTEGER} </update> </mapper>
package com.mifi.service; import java.util.List; import com.mifi.bean.MifiDevice; public interface MifiDeviceService { public boolean hasMifiDeviceById(long id); public MifiDevice getMifiDeviceById(long id); public List<MifiDevice> findAllMifiDevices(); public void addMifiDevice(MifiDevice mifiDevice); public void delMifiDeviceById(long id); public void updateMifiDevice(MifiDevice mifiDevice); }
package com.mifi.serviceimpl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.mifi.bean.MifiDevice; import com.mifi.dao.MifiDeviceDao; import com.mifi.service.MifiDeviceService; import com.netty.service.NettyServerService; @NettyServerService(name="mifiDeviceService") @Service public class MifiDeviceServiceImpl implements MifiDeviceService { @Autowired MifiDeviceDao dao; public boolean hasMifiDeviceById(long id){ return dao.getMifiDeviceById(id) == null ? false : true ; } public MifiDevice getMifiDeviceById(long id){ return dao.getMifiDeviceById(id); } public List<MifiDevice> findAllMifiDevices(){ return dao.findAllMifiDevices(); } public void addMifiDevice(MifiDevice mifiDevice){ dao.addMifiDevice(mifiDevice); } public void delMifiDeviceById(long id){ dao.delMifiDeviceById(id); } public void updateMifiDevice(MifiDevice mifiDevice){ dao.updateMifiDevice(mifiDevice); } }
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!
相关推荐
项目描述 说明: spring security 全注解式的权限管理 动态配置权限,角色和资源,权限控制到...Springboot+Mybatis+ SpringMvc+springsecrity+Redis+bootstrap+jquery 数据库文件 压缩包内 jar包文件 maven搭建
完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统(RESTful API+redis).zip 完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统(RESTful API+redis).zip 完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统...
基于 SpringBoot + Spring + SpringMvc + Mybatis + Shiro+ Redis 开发单点登录管理系统 基于 SpringBoot + Spring + SpringMvc + Mybatis + Shiro+ Redis 开发单点登录管理系统 基于 SpringBoot + Spring + ...
【标题】"spring+mybatis+springmvc 全注解框架"揭示了这是一个基于Java的Web开发框架,其中集成了Spring、MyBatis和SpringMVC这三个关键组件。Spring是全面的企业级应用框架,提供了依赖注入(DI)和面向切面编程...
本项目框架“maven+springMVC+mybatis+velocity+mysql+junit”提供了一种高效、灵活且可维护的解决方案。以下将详细讲解这些组件及其作用。 1. Maven: Maven是一个项目管理工具,用于构建、依赖管理和项目信息...
这是一个基于Java技术栈的完整网站后台管理系统,主要利用了Spring Boot、MyBatis、Spring MVC、Spring Security和Redis等核心技术。下面将详细讲解这些技术及其在系统中的作用。 首先,Spring Boot是Spring框架的...
在这样的背景下,结合MySQL数据库、Druid数据源以及PageHelper分页插件,我们可以构建一个高效的、具有分页功能的Web应用。下面将详细阐述这些技术点。 首先,Spring框架是Java企业级应用的核心组件,它提供了依赖...
基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis+Maven项目案例 基于SpringMVC+Spring+MyBatis...
【标题】"spring+mybatis+springmvc+ajax简单聊天室"揭示了这是一个基于Java技术栈构建的在线聊天室应用。这个项目的核心是利用Spring框架的各组件(Spring、MyBatis、SpringMVC)来处理后端逻辑,并通过Ajax实现...
Spring+SpringMVC+MyBatis+Shiro+MySQL+Redis+Maven+EasyUI+Bootstrap实现的通用权限管理系统。 Spring+SpringMVC+MyBatis+Shiro+MySQL+Redis+Maven+EasyUI+Bootstrap实现的通用权限管理系统 Spring+SpringMVC+...
Java基于Spring+SpringMVC+MyBatis实现的学生信息管理系统源码,SSM+Vue的学生管理系统。 Java基于Spring+SpringMVC+MyBatis实现的学生信息管理系统源码,SSM+Vue的学生管理系统。 Java基于Spring+SpringMVC+...
Spring Boot以其简洁、快速的起步方式深受开发者喜爱,而MyBatis作为轻量级的持久层框架,与Spring MVC结合能提供强大的数据访问能力。以下是详细的步骤和知识点讲解: 1. **安装与配置IDEA** 首先,确保你已经...
总结来说,"spring+springMVC+mybatis+quartz动态定时任务创建"这个技术栈利用Spring的全面性、Spring MVC的Web处理能力、MyBatis的数据访问效率以及Quartz的定时任务管理,构建出一个能够灵活应对各种定时需求的...
SSM框架,即Spring、SpringMVC和MyBatis,是Java Web开发中常见的三大框架。这三者结合,能够构建出高效、灵活且易于维护的Web应用。下面将详细介绍这三个框架及其整合过程。 **Spring框架**:Spring是Java企业级...
"SpringMvc+Spring+Mybatis+Maven+注解方式"是一个经典的Java后端技术栈,它整合了四个关键组件,为开发人员提供了强大的工具和框架支持。下面将详细讲解这四个组件及其整合方式。 1. **Spring Framework**: ...
Spring、SpringMVC、Mybatis、Velocity和Maven是Java Web开发中常用的一组技术栈,它们各自在软件开发的不同层面发挥着重要作用。这个压缩包文件的标题和描述表明,它提供了一个集成这些技术的演示项目,下面我们将...
Springboot Spring+SpringMVC+Mybatis+Thymeleaf3.0+Druid 有增删改查,有监控http://localhost:8080/druid/login.html 账号 root 密码 123
基于SpringMVC+Spring+MyBatis+Maven项目案例源码+数据库.zip 基于SpringMVC+Spring+MyBatis+Maven项目案例源码+数据库.zip 基于SpringMVC+Spring+MyBatis+Maven项目案例源码+数据库.zip 基于SpringMVC+Spring+...
在本项目中,"Spring+SpringMVC+Mybatis+Maven+bootstrap+ajax+jQuery整合开发简单的员工后台管理系统",我们看到一个基于Java技术栈的Web应用开发实例。这个系统利用了多个核心技术来构建一个功能完备的员工管理...