- public void getBookList(String publisher,String author){
- Map<String,Object> maps = new HashMap<String, Object>();
- maps.put("publisher", publisher);
- maps.put("author", author);
- this.getListByEntity("getBookList",maps);
- }
- <select id="getBookList" resultType="Book">
- SELECT * FROM bookinfo
- <where>
- <if test="publisher != null">
- publisher = #{publisher}
- </if>
- <if test="author != null">
- AND author = #{author}
- </if>
- </where>
- </select>
- public void getBookList(String author){
- this.getListByEntity("getBookListByAuthor",author);
- }
- <select id="getBookListByAuthor" parameterType="java.lang.String" resultType="Book">
- SELECT * FROM bookinfo
- <where>
- <if test="author != null">
- author = #{author}
- </if>
- </where>
- </select>
如下写法正解
- <select id="getBookListByAuthor" parameterType="java.lang.String" resultType="Book">
- SELECT * FROM bookinfo
- <where>
- <if test="_parameter != null">
- AND author = #{author}
- </if>
- </where>
- </select>