Dao层@Param注解使用

1、如果没有@Param注解
Dao层函数

public Integer getApplyStatus(Integer horse_id);

对应xml

<select id="getApplyStatus" parameterType="java.lang.Integer" resultType="java.lang.Integer">
	SELECT apply_status FROM horse_basic WHERE horse_id =#{arg0}
</select>

2、添加@Param注解,程序可读性更强
Dao层函数

public Integer getApplyStatus(@Param("horse_id")Integer horse_id);

对应的xml

<select id="getApplyStatus" parameterType="java.lang.Integer" resultType="java.lang.Integer">
	SELECT apply_status FROM horse_basic WHERE horse_id =#{horse_id}
</select>

3、采用@Param修饰Javabean对象
Dao层函数

public void abc (@Param("t") TestTable testTable);

xml中采用对象点属性方式获取数据

<select>
   select * from testTable where username = #{t.userName}
</select>

总结: 增加@Param是为了增加代码的可读性更强,xml中接收的是注解中值对应的,使代码更美观。没有也能够传递参数。

posted @ 2019-07-15 19:03  ah_lydms  阅读(509)  评论(0编辑  收藏  举报