From ee5ee5a5314f97051110c3a6de8b36b9f443af04 Mon Sep 17 00:00:00 2001 From: qiurunze Date: Mon, 21 Jan 2019 18:13:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++--- docs/mybatis-code.md | 8 ++++- .../miaosha/mybatis/Mapper/UserMapper.java | 3 ++ .../mybatis/controller/UbatisController.java | 14 +++++++- .../miaosha/mybatis/vo/TeacherListVo.java | 32 +++++++++++++++++++ src/main/resources/application.properties | 4 +-- .../resources/mybatis/mapper/userMapper.xml | 15 ++++++--- 7 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/geekq/miaosha/mybatis/vo/TeacherListVo.java diff --git a/README.md b/README.md index af794d4..6aa98f7 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ ### 以下所有内容都已完成,但是因内容多需逐渐整理上传! 专题的部分也会尽快上传更新! 立个flag 半年内吧争取全部更新完!各位稍安勿躁! -### [如要提交代码请先看--提交合并代码规范](/docs/code-criterion.md) +### [如要提交代码请先看--提交合并代码规范提交者的后面都会有署名方面大家问问题](/docs/code-criterion.md) | ID | Problem | Article | | --- | --- | :--- | @@ -101,9 +101,6 @@ #### Get Start 下载项目, 切换的项目根目录 - - - ```bash Linux/Mac: @@ -116,7 +113,6 @@ ``` 运行以上命令相关依赖便会安装完毕 启动GeekQMainApplication主类即可 - 若有对于./mvnw 不了解的请点击下方链接介绍 -###### [maven-wrapper介绍](/docs/maven-wrapper.md) +###### [maven-wrapper介绍(add by zhangkai)](/docs/maven-wrapper.md) diff --git a/docs/mybatis-code.md b/docs/mybatis-code.md index 5e244fc..80d882b 100644 --- a/docs/mybatis-code.md +++ b/docs/mybatis-code.md @@ -88,4 +88,10 @@ ### generatorConfig.xml 内容解析? 已在其中备注,详细内容请见generatorConfig.xml -### generatorConfig.xml 内容解析? \ No newline at end of file +### xml映射文件都会有一个dao接口,工作原理? + + Dao接口里的方法,是不能重载的,因为是全限名+方法名的保存和寻找策略。 + Dao接口的工作原理是JDK动态代理,Mybatis运行时会使用JDK动态代理为Dao接口生成代理proxy对象, + 代理对象proxy会拦截接口方法,转而执行MappedStatement所代表的sql,然后将sql执行结果返回。 + +### \ No newline at end of file diff --git a/src/main/java/com/geekq/miaosha/mybatis/Mapper/UserMapper.java b/src/main/java/com/geekq/miaosha/mybatis/Mapper/UserMapper.java index c59e052..70a3056 100644 --- a/src/main/java/com/geekq/miaosha/mybatis/Mapper/UserMapper.java +++ b/src/main/java/com/geekq/miaosha/mybatis/Mapper/UserMapper.java @@ -2,6 +2,7 @@ package com.geekq.miaosha.mybatis.Mapper; import com.geekq.miaosha.mybatis.entity.User; +import com.geekq.miaosha.mybatis.vo.TeacherListVo; import com.geekq.miaosha.mybatis.vo.TeacherVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -41,4 +42,6 @@ public interface UserMapper { public List getTeacherAndUserList( @Param("uId") List uId ); + public List getTeacherAndUserListVo(@Param("uId") Integer uId ); + } diff --git a/src/main/java/com/geekq/miaosha/mybatis/controller/UbatisController.java b/src/main/java/com/geekq/miaosha/mybatis/controller/UbatisController.java index 7541e80..bf11852 100644 --- a/src/main/java/com/geekq/miaosha/mybatis/controller/UbatisController.java +++ b/src/main/java/com/geekq/miaosha/mybatis/controller/UbatisController.java @@ -3,6 +3,7 @@ package com.geekq.miaosha.mybatis.controller; import com.geekq.miaosha.access.AccessLimit; import com.geekq.miaosha.mybatis.Mapper.UserMapper; import com.geekq.miaosha.mybatis.entity.User; +import com.geekq.miaosha.mybatis.vo.TeacherListVo; import com.geekq.miaosha.mybatis.vo.TeacherVo; import com.geekq.miaosha.redis.KeyPrefix; import com.geekq.miaosha.redis.RedisService; @@ -98,7 +99,18 @@ public class UbatisController { list.add(1); list.add(2); - List teacherAndUser = userMapper.getTeacherAndUserList(list ); + List teacherAndUser = userMapper.getTeacherAndUserList(list); System.out.println(teacherAndUser.size()); } + + /** + * 测试多表联合查询 in + */ + @RequestMapping(value = "/testAssc", produces = "text/html") + @ResponseBody + public void testAssc(){ + + List teacherAndUser = userMapper.getTeacherAndUserListVo(1 ); + System.out.println(teacherAndUser.toString()); + } } diff --git a/src/main/java/com/geekq/miaosha/mybatis/vo/TeacherListVo.java b/src/main/java/com/geekq/miaosha/mybatis/vo/TeacherListVo.java new file mode 100644 index 0000000..c3ef74b --- /dev/null +++ b/src/main/java/com/geekq/miaosha/mybatis/vo/TeacherListVo.java @@ -0,0 +1,32 @@ +package com.geekq.miaosha.mybatis.vo; + +import com.geekq.miaosha.mybatis.entity.User; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.List; + +@Setter +@Getter +public class TeacherListVo implements Serializable { + + + private String tId ; + + private Integer uId ; + + private String tName ; + + private User userList; + + @Override + public String toString() { + return "TeacherListVo{" + + "tId='" + tId + '\'' + + ", uId=" + uId + + ", tName='" + tName + '\'' + + ", userList=" + userList + + '}'; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6c07bc2..54ad6b7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,12 +23,12 @@ log4j.logger.java.sql.PreparedStatement=DEBUG #mybatis mybatis.type-aliases-package=com.geekq.miaosha.domain #开启驼峰转换 configuration config-location 不能同時存在 如果要走流程 请 放开注释 -mybatis.configuration.map-underscore-to-camel-case=true +#mybatis.configuration.map-underscore-to-camel-case=true #mybatis.mapperLocations = classpath:com/geekq/miaosha/dao/*.xml mybatis.mapperLocations=classpath:mybatis/mapper/*.xml #配置xml方式 因为与 mybatis.configuration.map-underscore-to-camel-case 仅用于测试 -#mybatis.config-location=classpath:mybatis/mybatis-config.xml +mybatis.config-location=classpath:mybatis/mybatis-config.xml #add mybatis mybatis. diff --git a/src/main/resources/mybatis/mapper/userMapper.xml b/src/main/resources/mybatis/mapper/userMapper.xml index 92184fe..88c8492 100644 --- a/src/main/resources/mybatis/mapper/userMapper.xml +++ b/src/main/resources/mybatis/mapper/userMapper.xml @@ -32,7 +32,7 @@ userMapper(userMapper.xml文件去除后缀)保证唯一性 - + - - - + + + + @@ -95,6 +98,10 @@ userMapper(userMapper.xml文件去除后缀)保证唯一性 + +