-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuDaoImpl.java
More file actions
73 lines (59 loc) · 2.13 KB
/
Copy pathMenuDaoImpl.java
File metadata and controls
73 lines (59 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.caozj.dao.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import com.caozj.dao.MenuDao;
import com.caozj.framework.util.jdbc.Jdbc;
import com.caozj.model.Menu;
/**
* 菜单dao实现类
*
* @author caozj
*
*/
@Repository("menuDao")
public class MenuDaoImpl implements MenuDao {
@Autowired
private Jdbc jdbc;
@Value("${dbType}")
private String dbType;
private static final String table = "menu";
@Override
public void add(Menu menu) {
String sql = null;
if ("mysql".equalsIgnoreCase(dbType)) {
sql = "insert into " + table + "(text,parentID,url,orderNo) values(?,?,?,?)";
} else if ("oracle".equalsIgnoreCase(dbType)) {
sql = "insert into " + table + "(id,text,parentID,url,orderNo) values(auto_incr_id.nextval,?,?,?,?)";
} else {
throw new RuntimeException("配置的数据库类型暂时不支持,请自己编写sql语句或者联系开发者支持新的数据库类型:" + dbType);
}
jdbc.updateForBoolean(sql, menu.getText(), menu.getParentID(), menu.getUrl(), menu.getOrderNo());
}
@Override
public void update(Menu menu) {
String sql = "update " + table + " set text =? ,parentID=?,url=?,orderNo=? where id = ? ";
jdbc.updateForBoolean(sql, menu.getText(), menu.getParentID(), menu.getUrl(), menu.getOrderNo(), menu.getId());
}
@Override
public void delete(int id) {
String sql = "delete from " + table + " where id = ? ";
jdbc.updateForBoolean(sql, id);
}
@Override
public List<Menu> listChildren(int parentID) {
String sql = "select * from " + table + " where parentID = ? order by orderNo";
return jdbc.queryForList(sql, Menu.class, parentID);
}
@Override
public int countChildren(int parentID) {
String sql = "select count(*) from " + table + " where parentID = ? ";
return jdbc.queryForInt(sql, parentID);
}
@Override
public Menu get(int id) {
String sql = "select * from " + table + " where id = ? ";
return jdbc.query(sql, Menu.class, id);
}
}