黑猴子的家:Stock(十 二) 创建 UserServiceImpl 接口实现类

1、serviceimpl包下 –> New -> Class

13909371-cd411f784e9d97a9.png

2、Name -> UserServiceImpl -> Finish

13909371-3aa67cd7d885b80a.png

3、UserServiceImpl 类的内容

package com.yg.serviceimpl;

import java.util.List;
import com.yg.dao.UserDao;
import com.yg.entity.User;
import com.yg.service.UserService;

public class UserServiceImpl implements UserService {

      UserDao userDao = new UserDao();

      /**
       * 用户登录 查询一个对象
       * @param user
       * @param pwd
       * @return
       */
      public User login(String user, String pwd) {
            String sql = "select * from k_user where userno=? And pwd=?";
            // Object[] params = { user, pwd };
            User usersingle = null;
            try {
                  usersingle = userDao.querySingle(sql, user, pwd);
            } catch (Exception e) {
                  e.printStackTrace();
            }
            return usersingle;
      }

      /**
       * 获取所有用户 查询一个集合
       * @return
       */
      public List<User> get_All_Users() {
            String sql = "select * from k_user order by id asc";
            List<User> userList = null;
            try {
                  userList = userDao.queryList(sql);
            } catch (Exception e) {
                  e.printStackTrace();
            }
            return userList;
      }

      /**
       * 插入数据
       * 
       * @param user
       * @return
       */
      public Boolean add_User(User user) {
            String sql = "insert into k_user(username,userno,pwd) values(?,?,?)";
            int update = 0;
            try {
                  update = userDao.update(sql,
                                                      user.getUsername(),
                                                      user.getUserno(),
                                                      user.getPwd());
            } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
            return update > 0;
      }

      /**
       * 删除数据
       * 
       * @param id
       * @return
       */
      public Boolean delete_User(String id) {
            String sql = "delete from k_user where id=?";
            int update = 0;
            try {
                  update = userDao.update(sql, id);
            } catch (Exception e) {
                  e.printStackTrace();
            }
            return update > 0;
      }

      /**
       * 修改
       * 
       * @param user
       * @return
       */
      public Boolean edit_User(User user) {
            String sql = "update k_user set username=?,userno=?,pwd=? where id=?";
            int update = 0;
            try {
                  update = userDao.update(sql, 
                                                      user.getUsername(),
                                                      user.getUserno(),
                                                      user.getPwd(),
                                                      user.getId());
            } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }
            return update > 0;
      }
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值