该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package cn.com.seegoo.autophone.DAO; import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport; import cn.com.seegoo.autophone.Beans.Client;
import cn.com.seegoo.autophone.Beans.Information; public class InformationDAO extends JdbcDaoSupport { private final String insertSql = "insert into manager_information (type,content,entering_time) values (?, ?,now())";
// now()只用于mysql数据库
private final String updateSql = "update manager_information set type = ?, content = ? where infoid = ?";
// 时间不改
public InformationDAO() { } private Information formInformation(ResultSet rs) throws SQLException {
final Information information = new Information();
information.setInfoid(rs.getInt("infoid"));
information.setType(rs.getString("type"));
information.setContent(rs.getString("content"));
information.setEntering_time(rs.getDate("entering_time"));
return information;
} private final class InformationMapper implements RowMapper {
// RowMapper 将查询到的每行记录信息都封装到一个entity类里边,方便使用。
@Override
public Information mapRow(ResultSet rs, int rowNum) throws SQLException {
final Information information = formInformation(rs);
return information;
} } public boolean add(final Information information) {
if (information == null) {
return false;
}
int count = getJdbcTemplate().update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(
Connection connection) throws SQLException {
final PreparedStatement insertStatement = connection
.prepareStatement(insertSql);
insertStatement.setString(1, information.getType());
insertStatement.setString(2, information.getContent());
return insertStatement;
}
});
return count > 0;
} public boolean remove(int id) {
if (id > 0) {
int count = getJdbcTemplate().update(
"delete from manager_information where infoid=?", id);
return count > 0;
}
return false;
} public boolean update(Information information) {
if (information == null || information.getInfoid() <= 0) {
return false;
}
int count = getJdbcTemplate().update(updateSql, information.getType(),
information.getContent(), information.getInfoid());
return count > 0;
} public List queryInformation(String sql) {
return getJdbcTemplate().query(sql, new InformationMapper());
} public List getAllInformation() {
return queryInformation("select * from manager_information order by infoid desc");
} }
这是对消息的DAO层,本来设计上没有问题
但是有20多个实体,也就是说要写20多个dao层