This commit is contained in:
qiurunze 2019-01-21 18:13:59 +08:00
parent 07c30f0321
commit ee5ee5a531
7 changed files with 70 additions and 14 deletions

View File

@ -44,7 +44,7 @@
### 以下所有内容都已完成,但是因内容多需逐渐整理上传! 专题的部分也会尽快上传更新! 立个flag 半年内吧争取全部更新完!各位稍安勿躁! ### 以下所有内容都已完成,但是因内容多需逐渐整理上传! 专题的部分也会尽快上传更新! 立个flag 半年内吧争取全部更新完!各位稍安勿躁!
### [如要提交代码请先看--提交合并代码规范](/docs/code-criterion.md) ### [如要提交代码请先看--提交合并代码规范提交者的后面都会有署名方面大家问问题](/docs/code-criterion.md)
| ID | Problem | Article | | ID | Problem | Article |
| --- | --- | :--- | | --- | --- | :--- |
@ -101,9 +101,6 @@
#### Get Start #### Get Start
下载项目, 切换的项目根目录 下载项目, 切换的项目根目录
```bash ```bash
Linux/Mac: Linux/Mac:
@ -116,7 +113,6 @@
``` ```
运行以上命令相关依赖便会安装完毕 运行以上命令相关依赖便会安装完毕
启动GeekQMainApplication主类即可 启动GeekQMainApplication主类即可
若有对于./mvnw 不了解的请点击下方链接介绍 若有对于./mvnw 不了解的请点击下方链接介绍
###### [maven-wrapper介绍](/docs/maven-wrapper.md) ###### [maven-wrapper介绍(add by zhangkai)](/docs/maven-wrapper.md)

View File

@ -88,4 +88,10 @@
### generatorConfig.xml 内容解析? ### generatorConfig.xml 内容解析?
已在其中备注,详细内容请见generatorConfig.xml 已在其中备注,详细内容请见generatorConfig.xml
### generatorConfig.xml 内容解析? ### xml映射文件都会有一个dao接口工作原理
Dao接口里的方法是不能重载的因为是全限名+方法名的保存和寻找策略。
Dao接口的工作原理是JDK动态代理Mybatis运行时会使用JDK动态代理为Dao接口生成代理proxy对象
代理对象proxy会拦截接口方法转而执行MappedStatement所代表的sql然后将sql执行结果返回。
###

View File

@ -2,6 +2,7 @@ package com.geekq.miaosha.mybatis.Mapper;
import com.geekq.miaosha.mybatis.entity.User; 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.mybatis.vo.TeacherVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -41,4 +42,6 @@ public interface UserMapper {
public List<TeacherVo> getTeacherAndUserList( @Param("uId") List<Integer> uId ); public List<TeacherVo> getTeacherAndUserList( @Param("uId") List<Integer> uId );
public List<TeacherListVo> getTeacherAndUserListVo(@Param("uId") Integer uId );
} }

View File

@ -3,6 +3,7 @@ package com.geekq.miaosha.mybatis.controller;
import com.geekq.miaosha.access.AccessLimit; import com.geekq.miaosha.access.AccessLimit;
import com.geekq.miaosha.mybatis.Mapper.UserMapper; import com.geekq.miaosha.mybatis.Mapper.UserMapper;
import com.geekq.miaosha.mybatis.entity.User; 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.mybatis.vo.TeacherVo;
import com.geekq.miaosha.redis.KeyPrefix; import com.geekq.miaosha.redis.KeyPrefix;
import com.geekq.miaosha.redis.RedisService; import com.geekq.miaosha.redis.RedisService;
@ -98,7 +99,18 @@ public class UbatisController {
list.add(1); list.add(1);
list.add(2); list.add(2);
List<TeacherVo> teacherAndUser = userMapper.getTeacherAndUserList(list ); List<TeacherVo> teacherAndUser = userMapper.getTeacherAndUserList(list);
System.out.println(teacherAndUser.size()); System.out.println(teacherAndUser.size());
} }
/**
* 测试多表联合查询 in
*/
@RequestMapping(value = "/testAssc", produces = "text/html")
@ResponseBody
public void testAssc(){
List<TeacherListVo> teacherAndUser = userMapper.getTeacherAndUserListVo(1 );
System.out.println(teacherAndUser.toString());
}
} }

View File

@ -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 +
'}';
}
}

View File

@ -23,12 +23,12 @@ log4j.logger.java.sql.PreparedStatement=DEBUG
#mybatis #mybatis
mybatis.type-aliases-package=com.geekq.miaosha.domain mybatis.type-aliases-package=com.geekq.miaosha.domain
#开启驼峰转换 configuration config-location 不能同時存在 如果要走流程 请 放开注释 #开启驼峰转换 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:com/geekq/miaosha/dao/*.xml
mybatis.mapperLocations=classpath:mybatis/mapper/*.xml mybatis.mapperLocations=classpath:mybatis/mapper/*.xml
#配置xml方式 因为与 mybatis.configuration.map-underscore-to-camel-case 仅用于测试 #配置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 #add mybatis
mybatis. mybatis.

View File

@ -32,7 +32,7 @@ userMapper(userMapper.xml文件去除后缀)保证唯一性
</resultMap> </resultMap>
<resultMap type="com.geekq.miaosha.mybatis.vo.TeacherVo" id="TandUResultMap"> <resultMap type="com.geekq.miaosha.mybatis.vo.TeacherListVo" id="TandUResultMap">
<!-- id表示查询结果集中唯一标识 <!-- id表示查询结果集中唯一标识
column:查询出的列名 column:查询出的列名
property:type所指定的POJO中的属性名 property:type所指定的POJO中的属性名
@ -42,9 +42,12 @@ userMapper(userMapper.xml文件去除后缀)保证唯一性
<!-- 对普通列的映射定义 --> <!-- 对普通列的映射定义 -->
<result column="t_id" property="tId"/> <result column="t_id" property="tId"/>
<result column="t_name" property="tName"/> <result column="t_name" property="tName"/>
<result column="name" property="name"/>
<result column="age" property="age"/> <!--property="supervisor"表明这是为了映射学生实体的
<result column="_address" property="address"/> supervisor属性。javaType="Teacher"用到了Teacher这个
别名定义并指出了supervisor属性的java类型-->
<association property="userList" javaType="com.geekq.miaosha.mybatis.entity.User" column="u_id" select="com.geekq.miaosha.mybatis.Mapper.getUser" >
</association>
</resultMap> </resultMap>
<sql id="base_column"> <sql id="base_column">
@ -95,6 +98,10 @@ userMapper(userMapper.xml文件去除后缀)保证唯一性
</select> </select>
<select id="getTeacherAndUserListVo" resultMap="TandUResultMap">
select * from teacher t where t.u_id = #{uId}
</select>
<!-- 插入自动递增--> <!-- 插入自动递增-->
<insert id="insert" parameterType="com.geekq.miaosha.mybatis.entity.User" <insert id="insert" parameterType="com.geekq.miaosha.mybatis.entity.User"
useGeneratedKeys="true" keyProperty="id"> useGeneratedKeys="true" keyProperty="id">