标签:tps res htm any interface 类型 href param inter
需求是想写一个按公司名字查询公司列表的功能,最开始的代码如下
Dao层接口如下
@MyBatisDao
public interface OfficeDao extends TreeDao<Office> {
List<Office> findCompanyNameList(String name);
}
mybatis的xml代码:
<select id="findCompanyNameList" parameterType="java.lang.String" resultType="com.pds.modules.sys.entity.Office">
SELECT id,name FROM sys_office where o.del_flag = ‘1‘
<if test="name!= null and name!= ‘‘">
AND name LIKE concat(‘%‘,#{name},‘%‘)
</if>
</select>
这样写会报错,大体意思是name没有Getter方法。
在接口参数里加上mybatis中的@param注解
@MyBatisDao
public interface OfficeDao extends TreeDao<Office> {
List<Office> findCompanyNameList(@Param("name")String name);
}
<select id="findCompanyNameList" parameterType="java.lang.String" resultType="com.pds.modules.sys.entity.Office">
SELECT id,name FROM sys_office where o.del_flag = ‘1‘
<if test="name!= null and name!= ‘‘">
AND name LIKE concat(‘%‘,#{name},‘%‘)
</if>
</select>
在xml的if里用”_parameter” 代表参数
<select id="findCompanyNameList" parameterType="java.lang.String" resultType="com.pds.modules.sys.entity.Office">
SELECT id,name FROM sys_office where o.del_flag = ‘1‘
<if test="_parameter!= null and _parameter!= ‘‘">
AND name LIKE concat(‘%‘,#{name},‘%‘)
</if>
</select>
可以看出,_parameter不能区分多个参数,而@param能。所以@param能传多个这样的参数
原文地址:https://www.cnblogs.com/thiaoqueen/p/9634495.html
标签:tps res htm any interface 类型 href param inter
原文地址:https://www.cnblogs.com/sanhao/p/11428298.html