1.单独一个参数
(1)直接进行传递
SysUserInfo getSysUserByUsername(String username);
<select id="getSysUserByUsername" resultType="com.fulan.entity.SysUserInfo">
select * from sys_user_info where username=#{username}
</select>
(2)用注解@param
SysUserInfo getSysUserByUsername(@Param("username")String username);
<select id="getSysUserByUsername" resultType="com.fulan.entity.SysUserInfo">
select * from sys_user_info where username=#{username}
</select>
但是不建议这样搞
2.多个参数
(1)用对象封装后传入
public int addResourceInfo(ResourceInfo resourceInfo);
<insert id="addResourceInfo" parameterType="com.fulan.entity.ResourceInfo">
INSERT INTO resource_info (resource_name, creator_id, created_time, last_modifier_id, last_modified_time)
VALUES (#{resourceName}, #{creatorId}, now(), NULL, NULL)
</insert>
(2)用@param注解
public int addResourceInfo(@Param("resourceName")String resourceName,@Param("creatorId")int creatorId);
<insert id="addResourceInfo">
INSERT INTO resource_info (resource_name, creator_id, created_time, last_modifier_id, last_modified_time)
VALUES (#{resourceName}, #{creatorId}, now(), NULL, NULL)
</insert>
(3)用map进行封装
public int addResourceInfo(Hashmap map);
<insert id="addResourceInfo" parameterType="com.fulan.entity.ResourceInfo">
INSERT INTO resource_info (resource_name, creator_id, created_time, last_modifier_id, last_modified_time)
VALUES (#{resourceName}, #{creatorId}, now(), NULL, NULL)
</insert>
如果map中存放的是封装的resource对象
<insert id="addResourceInfo" parameterType="com.fulan.entity.ResourceInfo">
INSERT INTO resource_info (resource_name, creator_id, created_time, last_modifier_id, last_modified_time)
VALUES (#{resource.resourceName}, #{resource.creatorId}, now(), NULL, NULL)
</insert>
上文中如果对象中封装对象也需要点出属性,@param传的是对象的话同。
个人认为@param是将参数装在一个map里,望各位大佬指教