使用spring操作数据库
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import com.chinasofti.ynyc.dao.TodoDao;
import com.chinasofti.ynyc.model.SystemModel;
import com.chinasofti.ynyc.model.TodoTypeModel;
import com.chinasofti.ynyc.model.TodoModel;
import com.chinasofti.ynyc.model.TypeTypeModel;
import com.chinasofti.ynyc.model.TypeModel;
public class TodoDaoImpl extends JdbcDaoSupport implements TodoDao{
public List<TodoModel> getTodo1(String userId, String sysId, int rowNum) {
String sql="SELECT URL,START_TIME,TITLE FROM TODO_INFO ti where "+
"ti.SYS_ID = '"+sysId+"' and ti.USER_ID = '"+userId+"' and ROWNUM <="+rowNum;
List list =getJdbcTemplate().queryForList(sql);
if(list==null||list.size()==0){
return null;
}
List<TodoModel> listTodo = new ArrayList();
for (Iterator i = list.iterator(); i.hasNext();)
{
Map map=(Map)i.next();
TodoModel todo=new TodoModel();
todo.setStartTime((Date)(map.get("START_TIME")));
todo.setTitle(String.valueOf(map.get("title")));
todo.setUrl(String.valueOf(map.get("URL")));
listTodo.add(todo);
}
return listTodo;
}
@Override
public List<TodoTypeModel> getTodo2(String userId, String sysId, int rowNum) {
String sql = "SELECT URL,START_TIME,TITLE,TYPE_ID1 FROM ("+
"SELECT ROW_NUMBER() OVER(PARTITION BY TYPE_ID1 ORDER BY TYPE_ID1) AS rnk,URL,START_TIME,TITLE,TYPE_ID1 "+
"FROM TODO_INFO ti where ti.SYS_ID = '"+sysId+"' and ti.USER_ID = '"+userId+"') t WHERE rnk<="+rowNum;
List list =getJdbcTemplate().queryForList(sql);
if(list==null||list.size()==0){
return null;
}
List<TodoTypeModel> listTodo = new ArrayList();
for (Iterator i = list.iterator(); i.hasNext();)
{
Map map=(Map)i.next();
TodoTypeModel todo=new TodoTypeModel();
todo.setStartTime((Date)(map.get("START_TIME")));
todo.setTitle(String.valueOf(map.get("title")));
todo.setUrl(String.valueOf(map.get("URL")));
todo.setTypeId((BigDecimal)map.get("TYPE_ID1"));
listTodo.add(todo);
}
return listTodo;
}