use of com.sharding.jdbc.entity.Course in project note by kebukeYi.
the class ShardingJdbcApplicationTests method addCourse.
@Test
public void addCourse() {
// 01 配置文件
for (int i = 0; i < 10; i++) {
Course c = new Course();
// c.setCid(Long.valueOf(i));
c.setCname("shardingsphere");
c.setUserId(Long.valueOf("" + (1000 + i)));
c.setCstatus("1");
courseMapper.insert(c);
// 未有主键时
// Logic SQL: INSERT INTO course ( cname, user_id,cstatus ) VALUES ( ?,?,? )
// Actual SQL: m1 ::: INSERT INTO course_1 ( cname,user_id, cstatus , cid) VALUES (?, ?, ?, ?)
// 手动设置主键时
// Logic SQL: INSERT INTO course ( cname, user_id,cstatus ) VALUES ( ?,?,?,?)
// Actual SQL: m1 ::: INSERT INTO course_1 ( cname,user_id, cstatus , cid) VALUES (?, ?, ?, ?) ::: [0, shardingsphere, 1000, 1]
}
}
use of com.sharding.jdbc.entity.Course in project note by kebukeYi.
the class ShardingJdbcApplicationTests method queryCourseByHint.
@Test
public void queryCourseByHint() {
// 02 配置文件 强制路由策略打开
HintManager hintManager = HintManager.getInstance();
// 直接 定死 分表路由
hintManager.addTableShardingValue("course", 2);
// 直接 定死 分库路由
// hintManager.addDatabaseShardingValue("coursedb",2);
// Logic SQL: SELECT cid,cname,user_id,cstatus FROM course
// Actual SQL: m1 ::: SELECT cid,cname,user_id,cstatus FROM course_2
// Actual SQL: m2 ::: SELECT cid,cname,user_id,cstatus FROM course_2
List<Course> courses = courseMapper.selectList(null);
courses.forEach(course -> System.out.println(course));
hintManager.close();
}
Aggregations