From a85090e0a2a48be80828de7894a52164432a215e Mon Sep 17 00:00:00 2001 From: Mohammad Zuber Khan Date: Thu, 9 Apr 2015 23:18:46 -0500 Subject: [PATCH] Fix the issues with MyBatis Mapping --- src/com/markz/testApp/config/DataConfig.java | 9 +++-- .../testApp/controller/MyTestController.java | 25 +++++++----- src/com/markz/testApp/dao/UserDetailDao.java | 18 --------- .../testApp/mappers/UserDetailsMapper.java | 2 + .../testApp/mappers/UserDetailsMapper.xml | 37 ++++++++++++++++++ .../testApp/persistence/UserDetailsMapper.xml | 29 -------------- .../markz/testApp/Objects/UserDetail.class | Bin 1212 -> 1388 bytes .../com/markz/testApp/config/DataConfig.class | Bin 499 -> 1975 bytes .../testApp/controller/MyTestController.class | Bin 1351 -> 1246 bytes .../testApp/mappers/UserDetailsMapper.class | Bin 0 -> 427 bytes .../testApp/mappers/UserDetailsMapper.xml | 37 ++++++++++++++++++ .../maven/SpringMVC/SpringMVC/pom.properties | 2 +- .../maven/SpringMVC/SpringMVC/pom.xml | 11 +++++- 13 files changed, 108 insertions(+), 62 deletions(-) delete mode 100644 src/com/markz/testApp/dao/UserDetailDao.java create mode 100644 src/com/markz/testApp/mappers/UserDetailsMapper.xml delete mode 100644 src/com/markz/testApp/persistence/UserDetailsMapper.xml create mode 100644 target/classes/com/markz/testApp/mappers/UserDetailsMapper.class create mode 100644 target/classes/com/markz/testApp/mappers/UserDetailsMapper.xml diff --git a/src/com/markz/testApp/config/DataConfig.java b/src/com/markz/testApp/config/DataConfig.java index 838b7af..5e19486 100644 --- a/src/com/markz/testApp/config/DataConfig.java +++ b/src/com/markz/testApp/config/DataConfig.java @@ -2,6 +2,7 @@ import javax.sql.DataSource; +import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; @@ -10,14 +11,14 @@ import org.springframework.jdbc.datasource.SimpleDriverDataSource; @Configuration -@MapperScan("com.markz.testApp.persistence") +@MapperScan("com.markz.testApp.mappers") public class DataConfig { @Bean public DataSource dataSource() { SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriverClass(com.mysql.jdbc.Driver.class); - String url = "jdbc:mysql://enliteinstance.c9a1yjg7i5cn.us-east-1.rds.amazonaws.com:3306:test"; + String url = "jdbc:mysql://enliteinstance.c9a1yjg7i5cn.us-east-1.rds.amazonaws.com:3306/test"; String username = "master"; String password = "enliteUs"; dataSource.setUrl(url); @@ -32,12 +33,12 @@ public DataSourceTransactionManager transactionManager() { } @Bean - public SqlSessionFactoryBean sqlSessionFactory() { + public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); sessionFactory.setTypeAliasesPackage("com.markz.testApp.objects"); - return sessionFactory; + return sessionFactory.getObject(); } } diff --git a/src/com/markz/testApp/controller/MyTestController.java b/src/com/markz/testApp/controller/MyTestController.java index decde8c..e0a2a0a 100644 --- a/src/com/markz/testApp/controller/MyTestController.java +++ b/src/com/markz/testApp/controller/MyTestController.java @@ -1,22 +1,29 @@ package com.markz.testApp.controller; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.markz.testApp.mappers.UserDetailsMapper; import com.markz.testApp.objects.UserDetail; @RestController public class MyTestController { - @RequestMapping(value="/users/{user}") - public UserDetail message(@PathVariable String user){ - UserDetail userDetail = new UserDetail(); - userDetail.setAge(21); - userDetail.setName(user); - userDetail.setUserId(user+"@markz.com"); - userDetail.setZip(53717); - - return userDetail; + @Autowired + UserDetailsMapper userDetailsMapper; + + @RequestMapping(value = "/users/{id}") + public UserDetail getUserById(@PathVariable int id) { + return userDetailsMapper.getUserDetail(id); } + + @RequestMapping(value = "/users") + public List userList() { + return userDetailsMapper.getAllUsers(); + } + } diff --git a/src/com/markz/testApp/dao/UserDetailDao.java b/src/com/markz/testApp/dao/UserDetailDao.java deleted file mode 100644 index cbd5f54..0000000 --- a/src/com/markz/testApp/dao/UserDetailDao.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.markz.testApp.dao; - -import java.util.List; - -import org.mybatis.spring.support.SqlSessionDaoSupport; - -import com.markz.testApp.objects.UserDetail; - -public class UserDetailDao extends SqlSessionDaoSupport { - - public List getAllUsers() { - return getSqlSession().selectList("getAllUsers"); - } - - public UserDetail getUserDetails(int id) { - return getSqlSession().selectOne("getgetUserDetail"); - } -} diff --git a/src/com/markz/testApp/mappers/UserDetailsMapper.java b/src/com/markz/testApp/mappers/UserDetailsMapper.java index 040025e..4224191 100644 --- a/src/com/markz/testApp/mappers/UserDetailsMapper.java +++ b/src/com/markz/testApp/mappers/UserDetailsMapper.java @@ -11,6 +11,8 @@ public interface UserDetailsMapper { // @Select("SELECT * FROM user_detail where user_id={#userId}") public UserDetail getUserDetail(int id); + public UserDetail getUserDetailByLoginId(String loginId); + // public int insertUserDetail(UserDetail userDetail); // public void updateUserDetail(UserDetail userDetail); diff --git a/src/com/markz/testApp/mappers/UserDetailsMapper.xml b/src/com/markz/testApp/mappers/UserDetailsMapper.xml new file mode 100644 index 0000000..045655b --- /dev/null +++ b/src/com/markz/testApp/mappers/UserDetailsMapper.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/markz/testApp/persistence/UserDetailsMapper.xml b/src/com/markz/testApp/persistence/UserDetailsMapper.xml deleted file mode 100644 index bf25639..0000000 --- a/src/com/markz/testApp/persistence/UserDetailsMapper.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/classes/com/markz/testApp/Objects/UserDetail.class b/target/classes/com/markz/testApp/Objects/UserDetail.class index 1e3f793e22cbaadc5319af8aef9575f88886e8d7..c32105baf8ca2051b809f58c092bf7d637c69824 100644 GIT binary patch literal 1388 zcma)*&u$V?6vod51_TFbk+ur9wo>UpOUGJuqiNE#F`*%Kfo0)tfGge#Gh}9P!7J%P zqm4-yK7bEp{LavZI2{rf+;jhY-#x!`?(qB12uj%25dM5~maXNx%I?1u zlpN#M283~|4^4ccM%a9%Y~>$dX;jp1;uQn6@2jvN>H2Rn5hjGIb^PUAA}cB99> zO`R6lmxgb;iz=Zw42m|Y4Hi{(TBIxvAPNo=MuV?n;X5^A$*xZMYYDalX*ipvc&d}m zM;hGR&`ir2yIuKO@!REQ55LQ=KpVI$j-N(JDpHDWVV=e}6r&7&xG0#T)*ymCh`T@4`sJw#^>TVfyo+gIjUM@koDghAE;vM~pQUzkC5B0=h5ka8r584Xeo rgH!;rH3x)0F$Q@O39=UksYZhAM}zEzL3RLAp98}G1qOK*yutIo)}Fa; literal 1212 zcma))O>fgc5Qb;-Ng{`|A!(r@(6l9AEj5TEs8ZDm$tWs^v^j9wBum(m*pcmU$X|j3 z2r8r=_yPPV#5+!^2-lI2<=xrccV?cM-QRz%e-Y6OdY-13puN5`HpkNaI5U0a`Nxxq z`L=hd`o3pgc*;FhzSN^MB?PTq%1_c9Nqe|Zq$wq+80>1t>?l{uk)FxkNI?u=EW66} zv}0dbr-H;ALAevh_IzpkT{)VnLACb(v;sWoq4LiH++w478#qIP9vNg%4pQ$%T58-@GIR#PxY5>t{dNty%YGU7 z&392H6vtdRsKY|K?O zPtRyvA5&K&L3Y9*n~@-U(I7ivkS&0eSAcMX8RQAoForu){}Sp*B@(1bt%dWlBjqcq rhe5UhQe6SUH_RaWkst?Qkljd-!)TC$Fh~s`^%Wre#2Ca3N`LkjRqw3M diff --git a/target/classes/com/markz/testApp/config/DataConfig.class b/target/classes/com/markz/testApp/config/DataConfig.class index 0d18e8d11d1a10ac1329e33d1b9f00b97302906b..8ead929109cf70827b05c8c02f9f565fb60fe911 100644 GIT binary patch literal 1975 zcmbtU?NZxD6g_K9Y#arG_y~li%|{^y$5sdlX$&PH5R$fr(3mij$*)Ch9Dyadl1w1a z(uZj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ZXg2XIwWc;?Ro|7mo(y* zCyH|4^>+Eb%<`;q@?4zc@-_LsOs*}7Qc1HjH0}wzOxjv_nb>^(Nl%{{2F}v03Jn`b z?+owcrFmCHuzhT3%0M^6;CUa<-`hkNn)T3Y;U;d;WBM|f(_V(-i;0Ym+_7*MePlC5 zmPsQ+>>`^p1_l_q>;0cED?2Ye6N4BsaQ{pJ)n3TL1H=iw>eI>=!_aB?nq+##df=3a zehljp>x&@CV9r(xd5mtYBV!gg#_2xv5Yow0t)E6csf~KnBe_-Z35y!#F+(J9YxxYF z@e74?Vba1=ZBjFtq^oK%-vIpnqy3wtPjZvzO?ih7zxgLa%|Mswrv0V3b3VUtE3225O| z(W)iT+(J8sRI7!eWoR#%TtfYH+7eVO3h^h+F56~UQGXFFdV6?N-Mb!RMRn{L?F mrJZ+O3 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/m2e-wtp/web-resources/META-INF/maven/SpringMVC/SpringMVC/pom.properties b/target/m2e-wtp/web-resources/META-INF/maven/SpringMVC/SpringMVC/pom.properties index 72227d8..2e04cb8 100644 --- a/target/m2e-wtp/web-resources/META-INF/maven/SpringMVC/SpringMVC/pom.properties +++ b/target/m2e-wtp/web-resources/META-INF/maven/SpringMVC/SpringMVC/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Mon Apr 06 23:57:30 CDT 2015 +#Thu Apr 09 23:15:12 CDT 2015 version=0.0.1-SNAPSHOT groupId=SpringMVC m2e.projectName=SpringMVC diff --git a/target/m2e-wtp/web-resources/META-INF/maven/SpringMVC/SpringMVC/pom.xml b/target/m2e-wtp/web-resources/META-INF/maven/SpringMVC/SpringMVC/pom.xml index 995ddfa..c87adb2 100644 --- a/target/m2e-wtp/web-resources/META-INF/maven/SpringMVC/SpringMVC/pom.xml +++ b/target/m2e-wtp/web-resources/META-INF/maven/SpringMVC/SpringMVC/pom.xml @@ -72,6 +72,15 @@ mybatis 3.2.8 - + + org.springframework + spring-jdbc + 4.1.4.RELEASE + + + mysql + mysql-connector-java + 5.1.35 + \ No newline at end of file