标签:spring poj nsa size 用户登录 err sel text png
1.使用SQL参照 JSP新闻列表显示
2.新增web项目,项目名称为ssmNewsList
基本项目结构如下:
3.分别创建applicationContext-dao.xml、applicationContext-service.xml、applicationContext-transaction.xml、springmvc.xml
及在web.xml中配置加载
4.src中分别创建dao controller service pojo包
controller中增加显示新闻列表的方法及详情方法
dao中增加新增查询
@Override public List<NewsBean> getNewsList() { List<Map<String,Object>> list=jdbcTemplate.queryForList("select * from news "); List<NewsBean> clist = new ArrayList<NewsBean>(); if(list!=null&&list.size()>0){ for(Map<String,Object> mapl:list){ NewsBean newsBean=new NewsBean(); newsBean.setId(mapl.get("id").toString()); newsBean.setTitle(mapl.get("title").toString()); newsBean.setConetnt(mapl.get("conetnt").toString()); newsBean.setAuthor(mapl.get("author").toString()); newsBean.setAddtime((Date)mapl.get("addtime")); clist.add(newsBean); } } return clist; } @Override public NewsBean getNews(String id) { NewsBean newsBean=null; Object [] obj=new Object[1]; obj[0]=id; List<Map<String,Object>> list=jdbcTemplate.queryForList("select * from news where id=?",obj); if(list!=null&&list.size()>0){ newsBean=new NewsBean(); for(Map<String,Object> map:list){ newsBean.setId(map.get("id").toString()); newsBean.setTitle(map.get("title").toString()); newsBean.setConetnt(map.get("conetnt").toString()); newsBean.setAuthor(map.get("author").toString()); newsBean.setAddtime((Date)map.get("addtime")); } } return newsBean; }
5.分别增加以下文件分别用于用户登录及新闻显示
6.显示效果如:
最终源码放在码云: https://gitee.com/lg_ui/ssmNewsList
标签:spring poj nsa size 用户登录 err sel text png
原文地址:https://www.cnblogs.com/beginner1/p/13198066.html