<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.spring.Mapper.ProductMapper">
<select id="getProduct" parameterType="com.spring.curd.Product" resultType="com.spring.curd.Product">
SELECT * FROM product WHERE name=#{name} AND pid=#{pid}
</select>
<select id="getProduct2" parameterType="java.lang.String" resultType="java.lang.String">
SELECT pid FROM product WHERE name=#{name}
</select>
<select id="getProduct3" parameterType="java.lang.String" resultType="hashmap">
SELECT pid,name FROM product WHERE name=#{name}
</select>
<select id="getProduct4" parameterType="java.lang.String" resultType="hashmap">
SELECT pid,name FROM product WHERE name=#{name}
</select>
<!-- 输入2个参数,返回一个参数 -->
<select id="getProduct5" resultType="java.lang.Integer">
SELECT pid,name FROM product WHERE name=#{name} and pid=#{pid}
</select>
<!-- 输入2个参数,返回一个参数 -->
<select id="getProduct5_1" resultType="java.lang.Integer">
SELECT pid,name FROM product WHERE name=#{0} and pid=#{1}
</select>
<!-- 输入2个参数,返回一个参数 -->
<select id="getProduct6" parameterType="hashmap" resultType="java.lang.Integer">
SELECT pid FROM product WHERE name=#{name} and pid=#{pid}
</select>
<insert id="addProduct" parameterType="com.spring.curd.Product" flushCache="true">
INSERT INTO product (pid,name,price) VALUES (#{pid},#{name},#{price})
</insert>
<update id="updateProduct" parameterType="com.spring.curd.Product">
UPDATE product SET name=#{name} WHERE pid=#{pid}
</update>
<delete id="deleteProduct" parameterType="int">
DELETE FROM product WHERE pid=#{pid}
</delete>
</mapper>
对应的java类如下:(方法名跟id要保持一致)
public interface ProductMapper {
/**
* 查询,传入一个对象,返回一个对象
* @param product
* @return
*/
public Product getProduct(Product product);
/**
* 返回一个参数
* @param name
* @return
*/
public List getProduct2(String name);
/**
* 返回一个查询结果,多个参数
* @param name
* @return
*/
public Map<String,Object> getProduct3(String name);
/**
* 返回多个查询结果,多个参数
* @param name
* @return
*/
public List< Map<String,Object>> getProduct4(String name);
/**
* 2个入参,返回一个出参,方法1,利用注解
* @param name
* @return
*/
public Integer getProduct5(@Param("name") String username, @Param("pid") int pid);
/**
* 2个入参,返回一个出参,方法2:利用索引,这种不好知道传入的参数name
* hashmap自带
* @param name
* @return
*/
public Integer getProduct5_1(String username, int pid);
/**
* 2个入参,返回一个出参,方法3:传入map
* hashmap自带
* @param name
* @return
*/
public Integer getProduct6(Map<String, Object> map);
}