DAO layer in SSM

Compared with SSH, the DAO layer only needs to write the interface, and does not need the implementation of the interface to operate the database

1. The interface needs to be in the same directory and the same name as the mapper.xml file

2.mapper file

 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>

The permission name of the interface corresponding to the namespace

In the select tag, the id corresponds to the method name in the interface;

        parameterType corresponds to the parameter type in the method

        resultType corresponds to the type of the return value of the method

 

3. sql block

 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>

  For common sql statements, sql code blocks can be extracted and imported and used when needed

  Quoting the sql block:

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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324887273&siteId=291194637