- 编写customer表的domain类作映射
@Setter@Getter
public class Customer {
private Integer cust_id;
private String cust_name;
private String cust_profession;
private String cust_phone;
private String email;
@Override
public String toString() {
return "Customer{" +
"cust_id=" + cust_id +
", cust_name='" + cust_name + '\'' +
", cust_profession='" + cust_profession + '\'' +
", cust_phone='" + cust_phone + '\'' +
", email='" + email + '\'' +
'}';
}
}
- Mapping中添加插入的sql语句
<?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="myTest">
<!--添加用户-->
<insert id="addCustomer" parameterType="demo1.Customer">
INSERT INTO customer (cust_name,cust_profession,cust_phone,email) VALUES
(#{cust_name},#{cust_profession},#{cust_phone},#{email})
</insert>
</mapper>
- 将Mapping配置到SqlMappingConfig中
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development"&g