2021-05-24

package com.rjxy.mybatis.test3;

public class User {
private int id;
private String name;
private int age;

public User() {
	super();
	// TODO Auto-generated constructor stub
}
public User(int id, String name, int age) {
	super();
	this.id = id;
	this.name = name;
	this.age = age;
}
public int getId() {
	return id;
}
public void setId(int id) {
	this.id = id;
}
public String getName() {
	return name;
}
public void setName(String name) {
	this.name = name;
}
public int getAge() {
	return age;
}
public void setAge(int age) {
	this.age = age;

}
@Override
public String toString() {
	return "User [id=" + id + ", name=" + name + ", age=" + age + "]";
}

}

package com.rjxy.mybatis.test3;

public class ConditionUser {
private String name;
private int minAge;
private int maxAge;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMinAge() {
return minAge;
}
public void setMinAge(int minAge) {
this.minAge = minAge;
}
public int getMaxAge() {
return maxAge;
}
public void setMaxAge(int maxAge) {
this.maxAge = maxAge;
}
public ConditionUser(String name, int minAge, int maxAge) {
super();
this.name = name;
this.minAge = minAge;
this.maxAge = maxAge;
}
public ConditionUser() {
super();
// TODO Auto-generated constructor stub
}
@Override
public String toString() {
return “ConditionUser [name=” + name + “, minAge=” + minAge + “, maxAge=” + maxAge + “]”;
}

}

package com.rjxy.mybatis.test4;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.rjxy.mybatis.test1.User;

import com.rjxy.mybatis.test3.ConditionUser;

import mybatisutils.MybatisUntils;

public class Test7 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	SqlSessionFactory factory = MybatisUntils.getFactory();
	SqlSession session = factory.openSession();
	
	String statemeng = "com.rjxy.mybatis.test4.userMapper.getUser";
	String name="0";
	name=null;
	ConditionUser par=new ConditionUser("%"+name+"%", 13, 18);
	List<User> list=session.selectList(statemeng, par);
	
	
	System.out.println(list);
	session.close();
}

}

<?xml version="1.0" encoding="UTF-8" ?> select * from d_user where name like #{name} and age between #{minAge} and #{maxAge} <?xml version="1.0" encoding="UTF-8"?>
<!-- 开发模式 -->
<environments default="development">
	<environment id="development">
		<!-- 设置数据库的相关功能JDBC -->
		<transactionManager type="JDBC" />
		<!-- 连接池:加快访问速度 -->
		<dataSource type="POOLED">
		<!-- 数据库驱动 -->
			<property name="driver" value="${driver}" />
			<property name="url" value="${url}" />
			<property name="username" value="${username}" />
			<property name="password" value="${password}" />
		</dataSource>
	</environment>
</environments>
<mappers>
    
    <mapper resource="com/rjxy/mybatis/test3/userMapper.xml"/>
    <mapper resource="com/rjxy/mybatis/test3/orderMapper.xml"/>
    <mapper resource="com/rjxy/mybatis/test3/classesMapper.xml"/>
    <mapper resource="com/rjxy/mybatis/test4/userMapper.xml"/>
    <mapper resource="com/rjxy/mybatis/test5/userMapper.xml"/>
    
</mappers>	
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210524170723215.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80Njg4MDcyNw==,size_16,color_FFFFFF,t_70)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值