热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

SpringSidedml操作

【修改】方法一:根据id改变他的状态。就一个字段时。首先循环去的id,然后在他的action里遍历的根据id(要修改的字段的idÿ

=========================================================【修改】

方法一:根据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修改所有的字段,并且弹出一个新页面】

页面传入的值:

                           

                                              

                                                        ${loginName} 

                                                        ${name} 

                                                        ${email} 

                                                        ${roleNames} 

                                                         

                                                                           修改 [d2] 

                                                                           删除

                                                                

                                                       

                                              

                                        

==========================================================【删除】====================================================================

页面传入的值

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内的值:

 

==========================================================【添加】====================================================================

页面传入的值:

增加新用户

 

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 getAllNode(){     

                   return nodeDao.getAll();

         }

 

/**

          * 使用属性过滤条件查询用户.

          */

         @Transactional(readOnly = true)

         public Page searchUser(final Page page, final List filters) {

                   return userDao.findPage(page, filters);

         }

 

         @Transactional(readOnly = true)

         public User findUserByLoginName(String loginName) {

                   return userDao.findUniqueBy("loginName", loginName);

         }

 

 

dao内的值:

 

==========================================================【动态加载页面】============================================================

页面传入的值

 

action内的值:

         private Page page = new Page(5);//每页5条记录

         page = accountManager.searchUser(page, filters);//保存到page里面

 

service内的值:

         public Page searchUser(final Page page, final List filters) {

                   return userDao.findPage(page, filters);

         }

dao内的值:

         public class UserDao extends HibernateDao

jsp页面的值:

         //默认的是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]


转:https://www.cnblogs.com/pujiajia/p/3287366.html



推荐阅读
author-avatar
惬听风吟jyy_802
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有