好贷网好贷款

SpringSide】dml简单版

发布时间:2016-12-5 4:31:32 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"SpringSide】dml简单版",主要涉及到SpringSide】dml简单版方面的内容,对于SpringSide】dml简单版感兴趣的同学可以参考一下。

=========================================================【修改】===================================================================== 方法一:根据id改变他的状态。就一个字段时。 首先循环去的id,然后在他的action里遍历的根据id(要修改的字段的id)查出实体对象,并且赋值setisnotice字段,最后save。 即:find——》set——》save String[] IdArray=ids.split(",");                             for(String tempId:IdArray){                                                                       Article temp=articleService.getArticleById(Long.parseLong(tempId));                                      temp.setIsnotice(1L);                                      articleService.saveArticle(temp);                             } 方法二: action里面:          public String changeIsnotice(){                                     try {                             String[] IdArray=ids.split(",");                             for(String tempId:IdArray){                                                                       articleService.updateIsnoticeState(tempId);                             }                    } catch (Exception e) {                             logger.error("显示出错!",e);                    }                    return RELOAD;          } service层里: public void updateIsnoticeState(String isnoticeIds)     {                    System.out.println("updateIsnoticeState........ik");        String hql = "update Article a set a.isnotice = 1 where a.articleid in ("+isnoticeIds+")";        Query query = this.articleDao.createQuery(hql);        query.executeUpdate();[d1]                         }   方式二:【根据id修改所有的字段,并且弹出一个新页面】 页面传入的值: <form id="mainForm" action="user.action" method="get">                             <s:iterator value="page.result">                                                <tr>                                                         <td>${loginName}&nbsp;</td>                                                         <td>${name}&nbsp;</td>                                                         <td>${email}&nbsp;</td>                                                         <td>${roleNames}&nbsp;</td>                                                         <td>&nbsp;                                                                            <a href="studentAction!input.action?id=${id}">修改</a>&nbsp;[d2]                                                                             <a href="studentAction!delete.action?id=${id}">删除</a>                                                                                                                          </td>                                                </tr>                                      </s:iterator>    </form> ==========================================================【删除】==================================================================== 页面传入的值 action内的值: @Override          public String delete() throws Exception {                    try {                             accountManager.deleteUser(id);                             addActionMessage("删除用户成功");[d3]                     } catch (Exception e) {                             // TODO Auto-generated catch block                             e.printStackTrace();                             addActionMessage("删除用户失败");                    }                    return RELOAD;          } // 添加删除操作要用这个封装数据          @Override          protected void prepareModel[d4] () throws Exception {                    if (id != null) {                             entity = accountManager.getUser(id);                    } else {                             entity = new User();                    }                             }   service内的值: /**           * 删除用户,如果尝试删除超级管理员将抛出异常.           */          public void deleteUser(Long id) {                    if (isSupervisor(id)) {                             logger.warn("操作员{}尝试删除超级管理员用户", SpringSecurityUtils.getCurrentUserName());                             throw new ServiceException("不能删除超级管理员用户");                    }                    userDao.delete(id);[d5]           }     dao内的值:   ==========================================================【添加】==================================================================== 页面传入的值: <a href="${ctx}/account/studentAction!input.action">增加新用户</a>   action内的值: @Override          public String save() throws Exception {                    accountManager.saveUser(entity);                    return RELOAD;          }     service内的值: public void saveUser(User entity) {                    userDao.save(entity);          }   dao内的值:   ==========================================================【查询】==================================================================== 页面传入的值   action内的值:     service内的值: //第一次页面加载所有数据          public List<Node> getAllNode(){                         return nodeDao.getAll();          }   /**           * 使用属性过滤条件查询用户.           */          @Transactional(readOnly = true)          public Page<User> searchUser(final Page<User> page, final List<PropertyFilter> filters) {                    return userDao.findPage(page, filters);          }            @Transactional(readOnly = true)          public User findUserByLoginName(String loginName) {                    return userDao.findUniqueBy("loginName", loginName);          }     dao内的值:   ==========================================================【动态加载页面】============================================================ 页面传入的值   action内的值:          private Page<User> page = new Page<User>(5);//每页5条记录          page = accountManager.searchUser(page, filters);//保存到page里面   service内的值:          public Page<User> searchUser(final Page<User> page, final List<PropertyFilter> filters) {                    return userDao.findPage(page, filters);          } dao内的值:          public class UserDao extends HibernateDao<User, Long> jsp页面的值:          <s:iterator value="page.result">//默认的是result属性。表示集合里的值   ===========================================================【底层dao】============================================================ 1)返回page分页:     busiGoodsDAO.findPage(page,hql); 2)返回list集合:         busiGoodsDAO.createQuery(hql).list();[d6]  3)返回String不重复:   this.busiGoodsDAO.createQuery(hql).uniqueResult().toString();[d7]  4)返回void:                 this.busiGoodsDAO.createQuery(hql);                             query.executeUpdate();                      [d1]更新操作。Sql语句  [d2]超链接,传id  [d3]  [d4]初始化数据,就实现了根据id获得整个实体类  [d5]调用dao的delete方法,只需要传入id即可,不需要写语句  [d6]  [d7]

上一篇:数据结构(2)——队
下一篇:X264中CAVLC码字的快速读取

相关文章

相关评论