service层:管理具体的功能的接口,具体业务逻辑层
package com.nz.service;
import java.util.List;
import com.nz.entity.BankAccount;
public interface JDBCService {
//查
public List<BankAccount> JDBCQuery();
//新增
public boolean JDBCAdd(BankAccount bankAccount);
//新增后查询
public List<BankAccount> JDBCAddQuery(BankAccount bankAccount);
}
impl层:是继承service,dao层具体的实现类
package com.nz.service.impl;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import com.nz.dao.JDBCDao;
import com.nz.entity.BankAccount;
import com.nz.service.JDBCService;
import com.nz.util.MySQLDriverUtil;
public class JDBCServiceImpl implements JDBCService{
//创建对象
JDBCDao jdbcDao = new JDBCDao();
@Override
public List<BankAccount> JDBCQuery() {
//初始化反参
List<BankAccount> list = new ArrayList<BankAccount>();
//查
try {
list = jdbcDao.JDBCSelect();
//尝试获取连接
Connection connection = MySQLDriverUtil.getConnect();
//关闭流
MySQLDriverUtil.flowClose(connection);
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
//新增
public boolean JDBCAdd(BankAccount bankAccount) {
try {
boolean bl = jdbcDao.JDBCInsert(bankAccount);
//尝试获取连接
Connection connection = MySQLDriverUtil.getConnect();
//关闭流
MySQLDriverUtil.flowClose(connection);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public List<BankAccount> JDBCAddQuery(BankAccount bankAccount) {
try {
boolean bl = jdbcDao.JDBCInsert(bankAccount);
List<BankAccount> list = jdbcDao.JDBCSelect();
return list;
} catch (Exception e) {
e.printStackTrace();
}finally{
//尝试获取连接
Connection connection = MySQLDriverUtil.getConnect();
//关闭流
MySQLDriverUtil.flowClose(connection);
}
return null;
}
}
最后
以上就是典雅睫毛最近收集整理的关于service层和impl的全部内容,更多相关service层和impl内容请搜索靠谱客的其他文章。
发表评论 取消回复