MyBatis多表关系模糊查询

这首先是前台页面的设计如下图

在这里插入图片描述
然后是Controller层调用service层:
在这里插入图片描述

service 层
在这里插入图片描述
service 层实现类
在这里插入图片描述

最后是mapper层(也是dao层)以及xml的配置

     /*  
	 * 模糊查询  
	 */  
    public List<Record> likeSelect(@Param("uName")String uName,@Param("eAddress")String eAddress,@Param("rNum")Integer rNum); 

xml配置 也是最重要的配置

   <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
	<!-- 一对多关系配置
				其中:column 为数据库里面的字段名
					  property 为实体类的字段名
	 --> 
    <mapper namespace="com.hp.mapper.UserMapper">
    	<resultMap type="com.hp.pojo.Record" id="myRecord">
    	<id column="r_id" property="rId"></id>
    	<result column="b_address" property="bAddress"/>
    	<result column="e_address" property="eAddress"/>
    	<result column="b_time" property="bTime"/>
    	<result column="e_time" property="eTime"/>
    	<result column="r_num" property="rNum"/>
    	<result column="r_total" property="rTotal"/>
    	<result column="r_state" property="rState"/>
    	<result column="t_id" property="tId"/>
    	<result column="u_id" property="uId"/>
    	<association property="type" javaType="com.hp.pojo.Type">
    		<id column="t_id" property="tId"/>
    		<result column="t_name" property="tName"/>
    		<result column="t_cost" property="tCost"/>
    		<result column="t_free" property="tFree"/>
    	</association>
    	<association property="user" javaType="com.hp.pojo.User">
    	<id column="u_id" property="uId"/>
    	<result column="u_code" property="uCode"/>
    	<result column="u_name" property="uName"/>
    	<result column="u_pwd" property="uPwd"/>
    	</association>
    	</resultMap>
    	
      
      <!-- 模糊查询 -->
      <select id="likeSelect" resultMap="myRecord">
      
      select 
    		 j.r_id,j.b_address,j.e_address,j.b_time,
       		 j.e_time,j.r_num, j.r_total,j.t_id,j.r_state,u.u_name,t.t_name
      from  
       		 j_record j LEFT JOIN j_user u on j.r_id=u.u_id left join j_type t on u.u_id=t.t_id
      <where>
      		<if test="rNum != null and rNum != '' ">
      			j.r_num like concat(concat("%",#{rNum}),"%")
      		</if>
      		
      		<if test="eAddress != null and eAddress != '' ">
      			or j.e_address like concat(concat("%",#{eAddress}),"%")
      		</if>
      		
      		<if test="uName != null and uName != '' ">
      			or u.u_name like concat(concat("%",#{eAddress}),"%")
      		</if>
    	</where>	 
    </select>	
    </mapper>

2019/9/9 9:13:43

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

幻’梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值