【发布时间】:2018-11-25 11:20:14
【问题描述】:
在处理涉及从数据库请求多种数据类型的项目时,我遇到了以下问题:
假设我有 2 个对应于数据库实体的 java 类:
Routes
public class Route {
public Route(int n, int region, Date fdate, boolean changed, int points,
int length) {
super();
this.n = n;
this.region = region;
this.fdate = fdate;
this.changed = changed;
this.points = points;
this.length = length;
}
}
运营商
public class Carrier {
public Carrier(...) {
this.id = src.getId();
this.name = src.getName();
this.instId = src.getInstId();
this.depotId = src.getDepotId();
}
如果是这样,创建 Dao 接口和类的正确方法是什么?我就是这么干的——
@Repository
public class CarrierDaoImpl implements CarrierDao{
@Autowired
DataSource dataSource;
public List<Carrier> getAllOrgs() { ... }
}
@Repository
public class RoutesDaoImpl implements RoutesDao {
@Autowired
DataSource dataSource;
public ArrayList<AtmRouteItem> getRoutes(AtmRouteFilter filter) { ... }
}
我正在为每个 java 类 item\db 实体创建一个 @Repository DAO,然后为有关运营商和路线的请求创建 2 个单独的控制器。像这样:
@RestController
@RequestMapping(path = "/routes")
public class RoutesController {
@Autowired
RoutesDao routesDao;
@GetMapping(value = {"/getRoutes/", "/getRoutes"})
public ArrayList<Route> getRoutes() { ... } }
对于控制器运营商也是如此。它是否正确,如果不正确,正确的方法是什么?
对不起样式问题,这是我关于stackoverflow的第一个问题:)
【问题讨论】:
标签: java spring spring-boot jdbc dao