增加fmq多数据源配置

parent 52602246
package com.cc.config;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
/**
* Created by summer on 2016/11/25.
*/
@Configuration
@MapperScan(basePackages = "com.cc.mapper.fmq", sqlSessionTemplateRef = "fmqSqlSessionTemplate")
public class DataSourceFmqConfig {
@Bean(name = "fmqDataSource")
@ConfigurationProperties(prefix = "spring.datasource.fmq")
public DataSource xzxtDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "fmqSqlSessionFactory")
public SqlSessionFactory xzxtSqlSessionFactory(@Qualifier("fmqDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mapper/fmq/*.xml"));
return bean.getObject();
}
@Bean(name = "fmqSqlSessionTemplate")
public SqlSessionTemplate xzxtSqlSessionTemplate(@Qualifier("fmqSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
......@@ -2,6 +2,7 @@ package com.cc.controller;
import com.cc.bean.AutoSysUser;
import com.cc.common.ResultMap;
import com.cc.service.UserFmqDmeoService;
import com.cc.service.UserXzxtDmeoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
......@@ -15,6 +16,8 @@ import java.util.List;
public class HelloController {
@Autowired
UserXzxtDmeoService userXzxtDmeoService;
@Autowired
UserFmqDmeoService userFmqDmeoService;
@GetMapping("/abc")
public String hello(Model model){
model.addAttribute("msg","你好");
......@@ -26,4 +29,10 @@ public class HelloController {
return userXzxtDmeoService.userAll();
}
@ResponseBody
@GetMapping("/fmqdemo")
public ResultMap fmqdemo(Model model){
return userFmqDmeoService.userAll();
}
}
package com.cc.mapper.fmq;
import com.cc.bean.User;
import java.util.List;
public interface UserFmqDemoMapper {
/**
* 获取所有用户
*
*
* @return
*/
List<User> userAll();
}
package com.cc.service;
import com.cc.common.ResultMap;
/**
* @author yutons
*/
public interface UserFmqDmeoService {
/**
* 登录逻辑
* 1、先根据用户名查询用户对象
* 2、如果有用户对象,则继续匹配密码
* 如果没有用户对象,则抛出异常
*
* @return
*/
ResultMap userAll();
}
package com.cc.service.serviceimpl;
import com.cc.bean.User;
import com.cc.common.ResultMap;
import com.cc.mapper.fmq.UserFmqDemoMapper;
import com.cc.mapper.xzxt.UserXzxtDemoMapper;
import com.cc.service.UserFmqDmeoService;
import com.cc.service.UserXzxtDmeoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.List;
@Service
public class UserServiceFmqDemoImpl implements UserFmqDmeoService {
private static final Logger logger = LoggerFactory.getLogger(UserServiceFmqDemoImpl.class);
@Resource
private UserFmqDemoMapper userFmqDemoMapper;
@Override
public ResultMap userAll() {
List<User> userlist=userFmqDemoMapper.userAll();
ResultMap resultMap=new ResultMap();
if (!StringUtils.isEmpty(userlist)) {
resultMap.setData(userlist);
return resultMap;
}
return resultMap ;
}
}
......@@ -5,14 +5,21 @@ spring:
driverClassName: com.mysql.jdbc.Driver
username: root
password: 123
# spring2.0此处为jdbc-url
# mysql
jdbc-url: jdbc:mysql://127.0.0.1:3306/mybatis
type: com.alibaba.druid.pool.DruidDataSource
xzxt:
driverClassName: oracle.jdbc.driver.OracleDriver
username: XZXT
password: XZXT
# spring2.0此处为jdbc-url
# oracle
jdbc-url: jdbc:oracle:thin:@127.0.0.1:1521:XZXT
type: com.alibaba.druid.pool.DruidDataSource
fmq:
driverClassName: oracle.jdbc.driver.OracleDriver
username: XZXT
password: XZXT
# oracle
jdbc-url: jdbc:oracle:thin:@127.0.0.1:1521:XZXT
type: com.alibaba.druid.pool.DruidDataSource
......
spring:
datasource:
#数据源基本配置
# 数据源基本配置
mysql:
driverClassName: com.mysql.jdbc.Driver
username: root
password: 123
# spring2.0此处为jdbc-url
# mysql
jdbc-url: jdbc:mysql://127.0.0.1:3306/mybatis
type: com.alibaba.druid.pool.DruidDataSource
xzxt:
driverClassName: oracle.jdbc.driver.OracleDriver
username: XZXT
password: XZXT
# spring2.0此处为jdbc-url
jdbc-url: jdbc:oracle:thin:@192.168.1.109:1521:XZXT
# oracle
jdbc-url: jdbc:oracle:thin:@127.0.0.1:1521:XZXT
type: com.alibaba.druid.pool.DruidDataSource
fmq:
driverClassName: oracle.jdbc.driver.OracleDriver
username: XZXT
password: XZXT
# oracle
jdbc-url: jdbc:oracle:thin:@127.0.0.1:1521:XZXT
type: com.alibaba.druid.pool.DruidDataSource
#schema:
# - classpath:sql/department.sql
# - classpath:sql/employee.sql
......
<?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.cc.mapper.fmq.UserFmqDemoMapper">
<resultMap id="BaseResultMap" type="com.cc.bean.AutoSysUser" >
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="birthday" property="birthday" jdbcType="VARCHAR"/>
<result column="gzzm_zcy" property="gzzmZcy" jdbcType="VARCHAR"/>
<result column="glybz" property="glybz" jdbcType="VARCHAR"/>
<result column="lrdwmc" property="lrdwmc" jdbcType="VARCHAR"/>
<result column="lrdwdm" property="lrdwdm" jdbcType="VARCHAR"/>
<result column="policemanid" property="policemanid" jdbcType="VARCHAR"/>
<result column="gzzm_play" property="gzzmPlay" jdbcType="VARCHAR"/>
<result column="grade" property="grade" jdbcType="VARCHAR"/>
<result column="sex" property="sex" jdbcType="VARCHAR"/>
<result column="username" property="username" jdbcType="VARCHAR"/>
<result column="password" property="password" jdbcType="VARCHAR"/>
<result column="true_name" property="trueName" jdbcType="VARCHAR"/>
<result column="unitcode" property="unitcode" jdbcType="VARCHAR"/>
<result column="gxsj" property="gxsj" jdbcType="VARCHAR"/>
<result column="lrsj" property="lrsj" jdbcType="VARCHAR"/>
<result column="scbz" property="scbz" jdbcType="VARCHAR"/>
<result column="unitname" property="unitname" jdbcType="VARCHAR"/>
<result column="tqyhbz" property="tqyhbz" jdbcType="VARCHAR"/>
<result column="gxr" property="gxr" jdbcType="VARCHAR"/>
<result column="lrr" property="lrr" jdbcType="VARCHAR"/>
<result column="ip" property="ip" jdbcType="VARCHAR"/>
<result column="default_model" property="defaultModel" jdbcType="VARCHAR"/>
<result column="remark" property="remark" jdbcType="VARCHAR"/>
<result column="default_desktop" property="defaultDesktop" jdbcType="VARCHAR"/>
<result column="lastlogintime" property="lastlogintime" jdbcType="VARCHAR"/>
<result column="lastchecktime" property="lastchecktime" jdbcType="VARCHAR"/>
<result column="theme" property="theme" jdbcType="VARCHAR"/>
<result column="gzzm_zhy" property="gzzmZhy" jdbcType="VARCHAR"/>
<result column="open_flag" property="openFlag" jdbcType="VARCHAR"/>
<result column="gzzm_ypy" property="gzzmYpy" jdbcType="VARCHAR"/>
<result column="identitycard" property="identitycard" jdbcType="VARCHAR"/>
<result column="telephone" property="telephone" jdbcType="VARCHAR"/>
<result column="xxzyurl" property="xxzyurl" jdbcType="VARCHAR"/>
</resultMap>
<!-- public Employee getEmpById(Integer id);
public void insertEmp(Employee employee);-->
<sql id="Base_Column_List">
birthday
,gzzm_zcy
,glybz
,lrdwmc
,lrdwdm
,policemanid
,gzzm_play
,grade
,sex
,username
,password
,true_name
,unitcode
,gxsj
,lrsj
,scbz
,unitname
,tqyhbz
,gxr
,lrr
,id
,ip
,default_model
,remark
,default_desktop
,lastlogintime
,lastchecktime
,theme
,gzzm_zhy
,open_flag
,gzzm_ypy
,identitycard
,telephone
,xxzyurl
</sql>
<select id="userAll" resultType="com.cc.bean.AutoSysUser">
SELECT * FROM sys_user
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment