DictionaryDao.java
3.65 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package vion.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import vion.model.Account;
import vion.model.Dictionary;
import vion.model.DictionaryType;
import java.util.List;
@Repository
public class DictionaryDao {
@Autowired
private JdbcTemplate jdbcTemplate;
private static final String SELECT_DICTIONARY_BY_UNID = "SELECT * FROM tbl_dictionary_info WHERE id=?";
public Dictionary getDictionaryById(Integer id) {
List<Dictionary> dictionaries= jdbcTemplate.query(SELECT_DICTIONARY_BY_UNID, new BeanPropertyRowMapper<Dictionary>(Dictionary.class), new Object[]{id});
if(dictionaries.size()>0){
return dictionaries.get(0);
}else{
return null;
}
}
private static final String SELECT_DICTIONARY_ALL= "SELECT * FROM tbl_dictionary_info";
public List<Dictionary> getDictionaryAll() {
return jdbcTemplate.query(SELECT_DICTIONARY_ALL, new BeanPropertyRowMapper<Dictionary>(Dictionary.class));
}
private static final String SAVE_DICTIONARY= "INSERT INTO tbl_dictionary_info(\n" +
" type, key, value, remark)\n" +
" VALUES (?, ?, ?, ?);";
public Integer addDictionary(Dictionary dictionary) {
return jdbcTemplate.update(SAVE_DICTIONARY,
new Object[]{
dictionary.getType(),dictionary.getKey(),dictionary.getValue(),dictionary.getRemark()});
}
private static final String UPDATE_DICTIONARY= "UPDATE tbl_dictionary_info\n" +
" SET type=?, key=?, value=?, remark=?\n" +
" WHERE id=?;";
public Integer updateDictionary(Dictionary dictionary) {
return jdbcTemplate.update(UPDATE_DICTIONARY,
new Object[]{
dictionary.getType(),dictionary.getKey(),dictionary.getValue(),dictionary.getRemark(),dictionary.getId()});
}
private static final String SELECT_TYPE_BY_UNID = "SELECT * FROM tbl_dictionary_type WHERE id=?";
public DictionaryType getDictionaryTypeById(Integer id) {
List<DictionaryType> dictionaries= jdbcTemplate.query(SELECT_TYPE_BY_UNID, new BeanPropertyRowMapper<DictionaryType>(DictionaryType.class), new Object[]{id});
if(dictionaries.size()>0){
return dictionaries.get(0);
}else{
return null;
}
}
private static final String SELECT_DICTIONARYTYPE_ALL= "SELECT * FROM tbl_dictionary_type";
public List<DictionaryType> getDictionaryTypeAll() {
return jdbcTemplate.query(SELECT_DICTIONARYTYPE_ALL, new BeanPropertyRowMapper<DictionaryType>(DictionaryType.class));
}
private static final String SAVE_DICTIONARYTYPE= "INSERT INTO tbl_dictionary_type(\n" +
" type, name, remark)\n" +
" VALUES (?, ?, ?);";
public Integer addDictionaryType(DictionaryType dictionaryType) {
return jdbcTemplate.update(SAVE_DICTIONARYTYPE,
new Object[]{
dictionaryType.getType(),dictionaryType.getName(),dictionaryType.getRemark()});
}
private static final String UPDATE_DICTIONARYTYPE= "UPDATE tbl_dictionary_type\n" +
" SET type=?, name=?, remark=?\n" +
" WHERE id=?;";
public Integer updateDictionaryType(DictionaryType dictionaryType) {
return jdbcTemplate.update(UPDATE_DICTIONARYTYPE,
new Object[]{
dictionaryType.getType(),dictionaryType.getName(),dictionaryType.getRemark(),dictionaryType.getId()});
}
}