mybatis MySQL 增删改查代码实现
①:添加依赖
|
②:编写pojo对象
public class Domen {
public Integer getUid() { public void setUid(Integer uid) { public String getUsername() { public void setUsername(String username) { public String getPwd() { public void setPwd(String pwd) { public String getSex() { public void setSex(String sex) { public String getAddress() { public void setAddress(String address) { |
|
③: 编写映射
<?xml version="1.0" encoding="utf-8" ?> </insert>
|
|
④:编写核心文件配置
<?xml version="1.0" encoding="UTF-8" ?> //下面是对数据库的连接:127.0.0.1:3306这个本机数据库端口号,wed0000 表名
value="jdbc:mysql://127.0.0.1:3306/wed0000"/> //密码 value="123456"/> |
⑤:测试框架
package cn.mph; import org.apache.ibatis.session.SqlSession; import java.io.InputStream; public class TextCustomerFram { } } SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); SqlSessionFactory build = builder.build(stream); SqlSession session = build.openSession(); Domen domen = new Domen(); }
|