Service

service是业务逻辑节点,方法中会包含业务逻辑处理过程,调用不同的Dao接口进行数据库的作业。

而且在Service一层会对业务逻辑进行事务控制。

package com.ntqingniao.sm.service;

 

import com.ntqingniao.sm.bean.Student;

import com.ntqingniao.sm.dao.IStudentDao;

import com.ntqingniao.sm.dao.impl.StudentDaoImpl;

 

public class StudentService {

public static void main(String[] args) throws Exception {

StudentService service = new StudentService();

//service.regStudent(new Student(null,"王五","wangwu","320611111111","123@qq.com",null));

System.out.println(service.activeStudent(214)?"success":"error");

}

private IStudentDao studentDao = new StudentDaoImpl();

/**

 * 学生注册

 * @param stu

 * @return

 * @throws Exception

 */

public Student regStudent(Student stu) throws Exception {

stu.setState(0); // 给学生的状态设置初始值0

return studentDao.addStudent(stu);

}

/**

 * 学生激活

 * @param id

 * @return

 * @throws Exception

 */

public boolean activeStudent(int id) throws Exception {

Student stu = studentDao.findStudentById(id);

// 如果能找到学生对象

if (null != stu) {

// 只有是初始状态下才能被激活

if (stu.getState() == 0) {

stu.setState(1);

boolean flag = studentDao.updateStudent(stu);

// 如果找到一个更新记录表示成功

if (flag) {

return true;

}

}

}

return false;

}

/**

 * 学生基本信息编辑

 * @param stu

 * @return

 */

public boolean editStudent(Student stu) {

return false;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值