About the use of typeAliases
When querying in Mybatis, parameterType is usually added to specify the parameter type. When the parameter is a class, we need to fully qualify the class name.
When a class belongs to many SQL statements, it will be more troublesome to write the fully qualified class name every time.
So Mybatis provided a typeAliases tag to help me solve this trouble.
The typeAliases tag is generally written in SqlMapConfig.xml, which is the xml of the configuration database, the code is as follows:
<typeAliases>
<typeAlias type="com.imis.pojo.Goods" alias="goods"></typeAlias>
</typeAliases>
Indicate the fully qualified class name and alias, in the future use only need to use the alias to replace the fully qualified class name
List<Goods> queryByCondition(Goods goods);
public void Test8(){
Goods goods=new Goods();
goods.setGoods_name("test1");
List<Goods> goods1 = iGoodsDao.queryByCondition(goods);
System.out.println(goods1);
}
<select id="queryByCondition" resultMap="goodsMap" parameterType="goods">
select * from goods where 1=1
<if test="goods_name!=null">
and name=#{goods_name}
</if>
</select>