parameterType和resultMap和resultType的区别
网上写的区别都不够直观,看起来真麻烦.,不讲区别光讲理论没意义的.
parameterType
前端发给后端的值,接到后指定类型,当然自己定义的实体类也可以 下面来个指定为Long类型的例子:
<select id="checkDeptExistUser" parameterType="Long" resultType="int"> select count(1) from sys_user where dept_id = #{deptId} and del_flag = 0 </select>
resultType
咱们后端发给前端的值,比如说resultType=“int”,返回给前端,当然自己定义的实体类也可以. 下面来个指定为int类型的例子:
<select id="countDictDataByType" resultType="Integer"> select count(1) from sys_dict_data where dict_type=#{dictType} </select>
返回的实体类,东西不能少,想要自定义就得用resultMap
resultMap
咱们后端发给前端的值(可自定义),自己定义的实体类有的值你不想怎么办嗯? 就用resultMap即可. 举个例子:
<?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"> <mapper namespace="com.ruoyi.system.mapper.SysConfigMapper"> <resultMap type="SysConfig" id="SysConfigResult"> <id property="configId" column="config_id"/> <result property="configName" column="config_name"/> <result property="configKey" column="config_key"/> ..... </resultMap> <select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult"> select config_id from sys_config where config_key = #{configKey} </select>
和resultType区别就说可以自定义,想返回什么字段就返回什么字段
下一篇:
mysql 之 删除数据表的方法