这首先是前台页面的设计如下图
然后是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