标签:开源项目 images bool 它的 class username org bit public
<?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>
<!-- mybatis的运行环境
数据库信息
事务
-->
<environments default="development">
<environment id="development">
<!-- jdbc事务 -->
<transactionManager type="JDBC" />
<!-- mybatis自身数据库连接池 -->
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:ORCL" />
<property name="username" value="scott" />
<property name="password" value="tiger" />
</dataSource>
</environment>
</environments>
<!-- 映射文件的信息 -->
<mappers>
<mapper resource="sqlmap/GoodsDAO.xml"/>
</mappers>
</configuration>
package cn.sxt.mybatis.vo; public class GoodsModel { private int uuid; private String name; private String description; private float price; public GoodsModel() { } public GoodsModel(int uuid, String name, String description, float price) { this.uuid = uuid; this.name = name; this.description = description; this.price = price; } public int getUuid() { return uuid; } public void setUuid(int uuid) { this.uuid = uuid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + Float.floatToIntBits(price); result = prime * result + uuid; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; GoodsModel other = (GoodsModel) obj; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (Float.floatToIntBits(price) != Float.floatToIntBits(other.price)) return false; if (uuid != other.uuid) return false; return true; } @Override public String toString() { return "GoodsModel [uuid=" + uuid + ", name=" + name + ", description=" + description + ", price=" + price + "]"; } }
<?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="goods">
<select id="getByUuid" parameterType="int" resultType="cn.sxt.mybatis.vo.GoodsModel">
select * from tbl_goods where uuid=#{uuid}
</select>
</mapper>
package cn.sxt.mybatis.test;
import java.io.IOException;
import java.io.InputStream;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import cn.sxt.mybatis.vo.GoodsModel;
public class TestApp {
public static void main(String[] args) throws IOException {
String resource = "SqlMapConfig.xml";
//根据全局配置文件得到输入流
InputStream inputStream = Resources.getResourceAsStream(resource);
//根据输入流创建SqlSessionFactory
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//根据SqlSessionFactory创建sqlSession
SqlSession sqlSession = sqlSessionFactory.openSession();
//操作
GoodsModel gm = sqlSession.selectOne("goods.getByUuid", 1);
System.out.println(gm);
sqlSession.close();
}
}
标签:开源项目 images bool 它的 class username org bit public
原文地址:http://www.cnblogs.com/huanhuan10/p/6745190.html