0.factory_c
CREATE TABLE `factory_c` (
`FACTORY_ID` varchar(40) NOT NULL,
`FULL_NAME` varchar(200) DEFAULT NULL,
`FACTORY_NAME` varchar(30) DEFAULT NULL,
`CONTRACTOR` varchar(20) DEFAULT NULL,
`PHONE` varchar(20) DEFAULT NULL,
`MOBILE` varchar(20) DEFAULT NULL,
`FAX` varchar(20) DEFAULT NULL,
`NOTE` varchar(600) DEFAULT NULL,
`ORDER_NO` int(11) DEFAULT NULL,
`STATE` int(11) DEFAULT NULL COMMENT '1启用0停用',
PRIMARY KEY (`FACTORY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 Factory .class
package com.jk.pojo; /** * @Description: * @Author: nutony * @Company: http://java.itcast.cn * @CreateDate: 2014-3-12 */ public class Factory { private String id; private String fullName; private String factoryName; private String contractor; private String phone; private String mobile; private String fax; private String cnote; public String getCnote() { return cnote; } public void setCnote(String cnote) { this.cnote = cnote; } private Integer orderNo; private Integer state; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getFullName() { return fullName; } public void setFullName(String fullName) { this.fullName = fullName; } public String getFactoryName() { return factoryName; } public void setFactoryName(String factoryName) { this.factoryName = factoryName; } public String getContractor() { return contractor; } public void setContractor(String contractor) { this.contractor = contractor; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public String getFax() { return fax; } public void setFax(String fax) { this.fax = fax; } public Integer getOrderNo() { return orderNo; } public void setOrderNo(Integer orderNo) { this.orderNo = orderNo; } public Integer getState() { return state; } public void setState(Integer state) { this.state = state; } }
2 mapper
package com.jk.mapper; import com.jk.pojo.Factory; import java.io.Serializable; import java.util.List; import java.util.Map; public interface FactoryMapper { List<Factory> find(Factory factory); Factory get(Serializable id); void insert(Factory factory); void update(Factory factory); void delete(Serializable id); void delteBatch(Serializable[] id); void changState(Map<String,Object> map); }
3 mapper.xml
<?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.jk.mapper.FactoryMapper"> <!-- 数据库表映射 --> <resultMap id="factoryRM" type="com.jk.pojo.Factory"> <id property="id" column="FACTORY_ID"/> <result property="fullName" column="FULL_NAME"/> <result property="factoryName" column="FACTORY_NAME"/> <result property="contractor" column="CONTRACTOR"/> <result property="phone" column="PHONE"/> <result property="mobile" column="MOBILE"/> <result property="fax" column="FAX"/> <result property="cnote" column="CNOTE"/> <result property="orderNo" column="ORDER_NO"/> <result property="state" column="STATE"/> </resultMap> <!-- 查询所有记录 --> <select id="find" parameterType="com.jk.pojo.Factory" resultMap="factoryRM"> select * from factory_c where 1=1 </select> <!--查询一个--> <select id="get" resultMap="factoryRM" parameterType="string"> SELECT * FROM factory_c WHERE factory_id=#{id} </select> <!--保存--> <insert id="insert" parameterType="com.jk.pojo.Factory"> INSERT INTO factory_c (FACTORY_ID,FULL_NAME,FACTORY_NAME,CONTRACTOR,PHONE,MOBILE,FAX,CNOTE,ORDER_NO,STATE) VALUES (UUID(),#{fullName},#{factoryName},#{contractor},#{phone},#{mobile},#{fax},#{cnote},#{orderNo},1) </insert> <!--修改--> <update id="update" parameterType="com.jk.pojo.Factory"> UPDATE factory_c <set> <if test="fullName!=null"> FULL_NAME=#{fullName} </if> <if test="factoryName!=null"> FACTORY_NAME=#{factoryName} </if> <if test="contractor!=null"> CONTRACTOR=#{contractor} </if> <if test="phone!=null"> PHONE=#{phone} </if> <if test="mobile!=null"> MOBILE=#{mobile} </if> <if test="fax!=null"> FAX=#{fax} </if><if test="cnote!=null"> CNOTE=#{cnote} </if> <if test="orderNo!=null"> ORDER_NO=#{orderNo} </if> </set> where FACTORY_ID=#{id} </update> <!--删除一条记录--> <delete id="delete" parameterType="string"> DELETE FROM factory_c WHERE FACTORY_ID=#{id} </delete> <!--批量删除--> <delete id="delteBatch" parameterType="string"> DELETE FROM factory_c WHERE FACTORY_ID IN <foreach collection="array" item="id" open="(" close=")" separator=","> #{id} </foreach> </delete> <!--修改状态 批量启用停用--> <update id="changState" parameterType="map"> UPDATE factory_c SET state=#{state} where FACTORY_ID in <foreach collection="ids" item="id" open="(" close=")" separator=","> #{id} </foreach> </update> </mapper>