的配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-////DTD Config 3.0//EN"
"/dtd/">
<configuration>
<!-- properties加载配置文件
-->
<properties resource=""></properties>
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
<environments default="dev">
<environment >
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${}"/>
<property name="url" value="${}"/>
<property name="username" value="${}"/>
<property name="password" value="${}"/>
</dataSource>
</environment>
</environments>
<mappers >
<mapper resource="com/bjsxt/mapper/"/>
</mappers>
</configuration>
:
=
=jdbc:mysql://192.168.5.129:3306/bjsxt
=root
=root
:
# Set root category priority to INFO and its only appender to CONSOLE.
=info, CONSOLE
# =DEBUG, CONSOLE, LOGFILE
# 单独设置SQL语句的输出级别为DEBUG级别
# 方法级别
# =DEBUG
# 类级别
# =DEBUG
# 包级别
=DEBUG
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
=.
=.
=- %m%l%n
# LOGFILE is set to be a File appender using a PatternLayout.
=.
=d:/
=true
=.
=- %m %l%n
User实体类
package ;
import ;
public class User implements Serializable{
private int id;
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
= id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
= username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
= password;
}
@Override
public String toString() {
return "User [, username=" + username + ", password=" + password + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((password == null) ? 0 : ());
result = prime * result + ((username == null) ? 0 : ());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != ())
return false;
User other = (User) obj;
if (id != )
return false;
if (password == null) {
if ( != null)
return false;
} else if (!())
return false;
if (username == null) {
if ( != null)
return false;
} else if (!())
return false;
return true;
}
public User() {
super();
}
}
selectList_selectOne_selectMap:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-////DTD Mapper 3.0//EN"
"/dtd/">
<mapper namespace="">
<select resultType="">
select * from t_user
</select>
<select resultType="">
select * from t_user where id=2
</select>
</mapper>
package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class TestSelect {
@Test
public void testSelectList() throws IOException {
InputStream is = ("");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
SqlSession session = ();
List<User> list = ("");
for (User user : list) {
(user);
}
();
}
@Test
public void testSelectOne() throws IOException {
InputStream is = ("");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
SqlSession session = ();
User u = ("");
(u);
();
}
@Test
public void testSelectMap() throws IOException {
InputStream is = ("");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
SqlSession session = ();
Map<Integer, User> map = ("", "id");
Set<Integer> ks = ();
for (Integer k : ks) {
((k));
}
();
}
}