上一篇文章搭建了 ssm 框架,使用的是mysql
ssm搭建:https://blog.csdn.net/qq_41463655/article/details/84176734
接下来连接 oracle,
更改逆向工程配置
jar 驱动包下载链接:https://pan.baidu.com/s/1AXP8f3OhtMNT3V63_bkryQ 密码:i9md
改为
在更改
改为
运行,生成了oracel 逆向工程文件,oracle 数据库表间自行创建了
更改 jdbc 配置文件
#jdbc.driver=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://localhost:3306/ssm_demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8
#jdbc.username=root
#jdbc.password=sweet
#最大连接数
c3p0.maxPoolSize=30
#最小连接数
c3p0.minPoolSize=10
#关闭连接后不自动commit
c3p0.autoCommitOnClose=false
#获取连接超时时间
c3p0.checkoutTimeout=10000
#当获取连接失败重试次数
c3p0.acquireRetryAttempts=2
#连接oracle数据库
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
jdbc.username=sweet2
jdbc.password=sweet2
添加oracle 连接的jar 依赖(不能使用maven,无授权),这里我 6 和14 版本都引入了
jar下载链接:https://pan.baidu.com/s/1HB_CKa_XlWpdbkCoVmivEg 密码:gtir
在这里插入代码片
创建 mapper 接口类
public interface EbItemMapper {
public EbItem selectByPrimaryKey(Integer id);
//查询所有
public List selectAll();
}
mapper.xml 添加查询所有 ,要求 id 和 dao 层方法名一致
测试类测试
类上注解别忘了
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({“classpath:spring-mybatis.xml”})
@Autowired
private EbItemMapper ebItemMapper;
//id查询
@org.junit.Test
public void selectItemId(){
EbItem ebItem = ebItemMapper.selectByPrimaryKey(1);
System.out.println(ebItem.toString());
}
//查询所有
@org.junit.Test
public void selectItemId(){
List ebItems = ebItemMapper.selectAll();
for (EbItem ebItem : ebItems){
System.out.println(ebItem.toString());
}
}