日期:2014-05-16 浏览次数:20493 次
<insert id="insertContact" parameterClass="contact"> insert into contact(NAME,GENDER,MOBILE,ADDRESS) values (#name:VARCHAR#,#gender:VARCHAR#,#mobile:VARCHAR#,#address:VARCHAR#) </insert>
package org.ourpioneer.contact.dao; import java.util.Map; import org.ourpioneer.contact.bean.Contact; public interface ContactDAO { public Contact getContactById(Map<Object, Object> parameterMap); public int insertContact(Contact contact); }
package org.ourpioneer.contact.dao.impl; import java.util.Map; import org.ourpioneer.contact.bean.Contact; import org.ourpioneer.contact.common.BaseDAO; import org.ourpioneer.contact.dao.ContactDAO; public class ContactDAOImpl extends BaseDAO implements ContactDAO { public Contact getContactById(Map<Object, Object> parameterMap) { return (Contact) getSqlMapClientTemplate().queryForObject( "getContactById", parameterMap); } public int insertContact(Contact contact) { return getSqlMapClientTemplate().update("insertContact", contact); } }
public int insertContact(Contact contact) { return getContactDAO().insertContact(contact); }
package org.ourpioneer.contact; import org.ourpioneer.contact.bean.Contact; import org.ourpioneer.contact.service.ContactService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class App { private static final Logger logger = LoggerFactory.getLogger(App.class); public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( "beans.xml"); ContactService contactService = (ContactService) context .getBean("contactService"); // Contact contact = contactService.getContactById(1); Contact contact = new Contact("Tom", "male", "15940990001", "Dalian"); int recordsOfUpdates = contactService.insertContact(contact); logger.info("{}", recordsOfUpdates); } }
public Contact() { super(); } public Contact(String name, String gender, String mobile, String address) { super(); this.name = name; this.gender = gender; this.mobile = mobile; this.address = address; }
<ins