Skip to content

Commit e059e1f

Browse files
committed
分离sql
1 parent be53367 commit e059e1f

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

multipleSource/src/main/java/info/xiaomo/multipleSource/controller/MultipleSourceController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package info.xiaomo.multipleSource.controller;
22

33
import info.xiaomo.core.controller.Result;
4+
import info.xiaomo.multipleSource.sql.Sql;
45
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.beans.factory.annotation.Qualifier;
67
import org.springframework.jdbc.core.JdbcTemplate;
@@ -40,11 +41,11 @@ public MultipleSourceController(@Qualifier("primaryJdbcTemplate") JdbcTemplate j
4041
@RequestMapping("/")
4142
public Result index() {
4243
// 往第一个数据源中插入两条数据
43-
jdbcTemplate1.update("insert into user(name,age) values(?, ?)", "xiaomo", 20);
44-
jdbcTemplate2.update("insert into user(name,age) values(?, ?)", "xiaoming", 30);
44+
jdbcTemplate1.update(Sql.addUser1, "xiaomo", 20);
45+
jdbcTemplate2.update(Sql.addUser1, "xiaoming", 30);
4546

46-
int count1 = jdbcTemplate1.queryForObject("select count(1) from user", Integer.class);
47-
int count2 = jdbcTemplate2.queryForObject("select count(1) from user", Integer.class);
47+
int count1 = jdbcTemplate1.queryForObject(Sql.selectUser1, Integer.class);
48+
int count2 = jdbcTemplate2.queryForObject(Sql.selectUser2, Integer.class);
4849
return new Result(new Object[]{count1, count2});
4950
}
5051
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package info.xiaomo.multipleSource.sql;
2+
3+
/**
4+
* 把今天最好的表现当作明天最新的起点..~
5+
* いま 最高の表現 として 明日最新の始発..~
6+
* Today the best performance as tomorrow newest starter!
7+
* Created by IntelliJ IDEA.
8+
*
9+
* @author: xiaomo
10+
* @github: https://github.com/qq83387856
11+
* @email: hupengbest@163.com
12+
* @QQ_NO: 83387856
13+
* @Date: 2016/11/16 11:29
14+
* @Description: 用户实体类
15+
* @Copyright(©) 2015 by xiaomo.
16+
**/
17+
18+
public class Sql {
19+
20+
public static String addUser1= "insert into user(name,age) values(?, ?)";
21+
public static String addUser2= "insert into user(name,age) values(?, ?)";
22+
23+
public static String selectUser1 = "select count(1) from user";
24+
public static String selectUser2 = "select count(1) from user";
25+
26+
}

0 commit comments

Comments
 (0)