SSM中的DAO层


相比较与SSH,DAO层只需要编写接口即可,并不需要接口的实现来对数据库进行操作

1.接口需与mapper.xml文件在同一个目录且同名

2.mapper文件

 1 <mapper namespace="com.hero.dao.BaseDictDao">
 2     
 3     <select id="getBaseDictByCode" parameterType="string" resultType="BaseDict">
 4             SELECT
 5                 *
 6             FROM
 7                 base_dict
 8             WHERE
 9                 dict_type_code =#{typeCode}
10     </select>
11     
12   </mapper>

namespace对应接口的权限名

在select标签中,id 对应接口中的方法名;

        parameterType 对应方法中的参数类型

        resultType 对应方法返回值的类型

 

3.sql块

 1 <sql id="cust_list_where">
 2         <where>
 3             <if test="custName !=null and custName !=''">
 4                 and cust_name like '%${custName}%'
 5             </if>
 6             <if test="custSource !=null and custSource !=''">
 7                 and cust_source=#{custSource}
 8             </if>
 9             <if test="custIndustory !=null and custIndustory !=''">
10                 and cust_industry=#{custIndustory}
11             </if>
12             <if test="custLevel !=null and custLevel != ''">
13                 AND cust_level = #{custLevel}
14             </if>
15         </where>
16     </sql>

  对于公共的sql语句,可以抽取出来sql代码块,在需要的时候引入即可使用

  引用sql块:

1 <include refid="cust_list_where"></include>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM