摘要:項(xiàng)目主要是在框架下對雙數(shù)據(jù)源進(jìn)行配置和操作的實(shí)例,關(guān)于框架搭建這里就不予展示與介紹了,想了解的請參考之前的項(xiàng)目介紹項(xiàng)目代碼獲取功能分類增刪改查雙數(shù)據(jù)源切換對類型和類型進(jìn)行緩存插入與讀取項(xiàng)目結(jié)構(gòu)代碼雙數(shù)據(jù)源配置相關(guān)類數(shù)據(jù)庫交互層實(shí)體對象層相
redis-mongo
項(xiàng)目主要是在spring、springmvc、mybatis框架下對mysql、mysql雙數(shù)據(jù)源、redis、mongo進(jìn)行配置和操作的實(shí)例,關(guān)于框架搭建這里就不予展示與介紹了,想了解的請參考之前的shiro項(xiàng)目介紹
項(xiàng)目代碼獲取:https://github.com/pysasuke/r...
mysql增刪改查
mysql雙數(shù)據(jù)源切換
redis對String類型和Object類型進(jìn)行緩存
mongo插入與讀取
項(xiàng)目結(jié)構(gòu) java:代碼core:雙數(shù)據(jù)源配置相關(guān)類
dao:數(shù)據(jù)庫交互層
entity:實(shí)體對象層
util:redis相關(guān)工具類
resources:配置文件mapping:mybatis與實(shí)體映射文件存放包
application.xml:spring配置文件入口,加載spring-config.xml
spring-mvc.xml:springmvc配置相關(guān)文件
spring-config.xml:加載其他集成的配置文件
spring-mybatis.xml:mybatis相關(guān)配置文件
spring-mongo.xml:mongo相關(guān)配置文件
spring-redis.xml:redis相關(guān)配置文件
db.properties:數(shù)據(jù)庫相關(guān)參數(shù)配置
log4j.properties:日志相關(guān)參數(shù)配置
redis.properties:redis相關(guān)參數(shù)配置
webapp:web相關(guān)web.xml
test:測試包doubleMysql:雙數(shù)據(jù)源測試包
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application.xml") //加載xml文件 public class TestDoubleMysql { @Autowired private ImuserMapper imuserMapper; @Autowired private TuserMapper tuserMapper; @Test public void test() { IMUser imUser = generateIMUser(); DataSourceContextHolder.setDBType(DataSourceType.DB_IM); int row_im = imuserMapper.insert(imUser); Assert.assertEquals(1, row_im); DataSourceContextHolder.clearDBType(); Tuser tuser = generateTuser(); DataSourceContextHolder.setDBType(DataSourceType.DB_ERP); int row_t = tuserMapper.insert(tuser); Assert.assertEquals(1, row_t); DataSourceContextHolder.clearDBType(); } private IMUser generateIMUser() { IMUser imUser = new IMUser(); imUser.setUsername("lisi"); imUser.setPassword("123456"); imUser.setNickname("huahua"); imUser.setEmail("123456@qq.com"); imUser.setMobile("18650140605"); return imUser; } private Tuser generateTuser() { Tuser tuser = new Tuser(); tuser.setUsername("zhangsan"); tuser.setPassword("123456"); tuser.setMobile("13666666666"); tuser.setEmail("123456@qq.com"); return tuser; } }
mongo:mongo測試包
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application.xml") public class TestMongo { @Resource private MongoTemplate mongoTemplate; @Test public void test() { MgUser mgUser = new MgUser(); mgUser.setId(1L); mgUser.setNikename("pysasuke"); mgUser.setPhone("18650140605"); //插入成功后_id屬性有值(mongo數(shù)據(jù)庫生成的) mongoTemplate.insert(mgUser); MgUser selectMgUser = mongoTemplate.findOne(new Query(Criteria.where("id").is(1L)), MgUser.class); Assert.assertEquals(mgUser.getId(), selectMgUser.getId()); } }
mysql:mysql測試包
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application.xml") //加載xml文件 public class TestMysql { @Autowired private TuserMapper tuserMapper; @Test public void testInsert() { Tuser tuser = generateTuser(); int row = tuserMapper.insert(tuser); Assert.assertEquals(1, row); } @Test public void testSelect() { Tuser tuser = generateTuser(); /* 插入成功后id會有值(mysql數(shù)據(jù)庫生成的) 前提是: 1.主鍵設(shè)置為自動(dòng)增長 2.xml中insert語句設(shè)置有:useGeneratedKeys="true" keyProperty="id" */ int row = tuserMapper.insert(tuser); Assert.assertEquals(1, row); Tuser selectedTuser = tuserMapper.selectByPrimaryKey(tuser.getId()); Assert.assertNotNull(selectedTuser); Assert.assertEquals(tuser, selectedTuser); } @Test public void testUpdate() { Tuser tuser = generateTuser(); int row = tuserMapper.insert(tuser); Assert.assertEquals(1, row); Tuser selectedTuser = tuserMapper.selectByPrimaryKey(tuser.getId()); Assert.assertNotNull(selectedTuser); selectedTuser.setPassword("654321"); tuserMapper.updateByPrimaryKeySelective(selectedTuser); Tuser updatedTuser = tuserMapper.selectByPrimaryKey(selectedTuser.getId()); Assert.assertNotNull(updatedTuser); Assert.assertEquals(selectedTuser.getPassword(), updatedTuser.getPassword()); } @Test public void testDelete() { Tuser tuser = generateTuser(); int row = tuserMapper.insert(tuser); Assert.assertEquals(1, row); tuserMapper.deleteByPrimaryKey(tuser.getId()); Tuser selectedTuser = tuserMapper.selectByPrimaryKey(tuser.getId()); Assert.assertNull(selectedTuser); } private Tuser generateTuser() { Tuser tuser = new Tuser(); tuser.setUsername("zhangsan"); tuser.setPassword("123456"); tuser.setMobile("13666666666"); tuser.setEmail("123456@qq.com"); return tuser; } }
redis:redis測試包
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application.xml") public class TestRedis { @Autowired private RedisCache cache; @Test public void testPutString() { cache.putCacheWithExpireTime("testPutString", "123456", 60); } @Test public void tesGetString() { cache.putCacheWithExpireTime("tesGetString", "123456", 60); String str = cache.getCache("tesGetString", String.class); Assert.assertEquals("123456", str); } @Test public void testObject() { Person person = generatePerson(); cache.putCacheWithExpireTime("testObject:" + person.getUsername(), person, 600); } @Test public void tesGetObject() { Person person = generatePerson(); cache.putCacheWithExpireTime("tesGetObject:" + person.getUsername(), person, 600); Person cachePerson = cache.getCache("tesGetObject:"+person.getUsername(), Person.class); Assert.assertEquals(person, cachePerson); } @Test public void tesDeleteCache() { cache.putCacheWithExpireTime("tesDeleteCache", "123456", 60); String cacheStr = cache.getCache("tesDeleteCache", String.class); Assert.assertEquals("123456", cacheStr); cache.deleteCache("tesDeleteCache"); String DeleteStr = cache.getCache("tesDeleteCache", String.class); Assert.assertNull(DeleteStr); } private Person generatePerson() { Person person = new Person(); person.setId(1L); person.setUsername("wangwu"); person.setPassword("123456"); return person; } }其他文件 logs:日志存放 deploy:部署文件(sql)
update.sql
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/19095.html
摘要:項(xiàng)目主要是在框架下對雙數(shù)據(jù)源進(jìn)行配置和操作的實(shí)例,關(guān)于框架搭建這里就不予展示與介紹了,想了解的請參考之前的項(xiàng)目介紹項(xiàng)目代碼獲取功能分類增刪改查雙數(shù)據(jù)源切換對類型和類型進(jìn)行緩存插入與讀取項(xiàng)目結(jié)構(gòu)代碼雙數(shù)據(jù)源配置相關(guān)類數(shù)據(jù)庫交互層實(shí)體對象層相 redis-mongo 項(xiàng)目主要是在spring、springmvc、mybatis框架下對mysql、mysql雙數(shù)據(jù)源、redis、mongo進(jìn)...
摘要:作者重慶森林鏈接來源牛客網(wǎng)整個(gè)三月份通過牛客網(wǎng)和網(wǎng)友分享的經(jīng)驗(yàn)學(xué)到了很多東西,現(xiàn)在反饋一下我的面試經(jīng)歷,希望對同學(xué)們有幫助。個(gè)人情況大三本方向渣碩,經(jīng)過實(shí)驗(yàn)室學(xué)長內(nèi)推,于三月底完成面試。校招是實(shí)力和運(yùn)氣的結(jié)合,缺一不可。 歡迎關(guān)注我的微信公眾號:Java面試通關(guān)手冊(堅(jiān)持原創(chuàng),分享美文,分享各種Java學(xué)習(xí)資源,面試題,以及企業(yè)級Java實(shí)戰(zhàn)項(xiàng)目回復(fù)關(guān)鍵字免費(fèi)領(lǐng)取):showImg(h...
閱讀 989·2021-11-24 09:39
閱讀 2210·2021-11-16 11:54
閱讀 2092·2021-11-11 17:22
閱讀 2379·2021-09-30 09:55
閱讀 3607·2021-08-12 13:22
閱讀 1633·2019-08-30 15:44
閱讀 1179·2019-08-29 12:12
閱讀 3271·2019-08-27 10:58