spring+mybatis的三层架构

在每个功能模块中的分层(mybatis映射接口层、持久层(dao)、业务层(service)、表现层(controller))

持久层开始调用方式:(持久层调用mybatis映射接口层)

@Repository
public class LoginLogDaoImpl implements ILoginLogDao {

	@Resource
	private LoginLogMapper mapper;
	
	@Override
	public int addLoginLog(LoginLogBean logBean) {
		return mapper.addLoginLog(logBean);
	}
}

业务层调用方式(业务层调用持久层接口)

@Service
public class LoginLogServiceImpl implements ILoginLogService {

	@Resource
	private ILoginLogDao loginLogDaoImpl;
	
	@Override
	public int addLoginLog(LoginLogBean logBean) {
		
		return loginLogDaoImpl.addLoginLog(logBean);
	}
}

表现层调用方式(表现层调用业务层)

@RequestMapping("/users")
@Controller
public class UserController {

    @Resource
    private ILoginLogService loginLogServiceImpl;
	
    @RequestMapping("/add")
    @ResponseBody
    public ResMessage addLoginLog(LoginLogBean logBean) {
        ResMessage msg = new ResMessage(true, "操作成功!");
		
        try {
            loginLogServiceImpl.addLoginLog(logBean);
          } catch (Exception e) {
            // TODO: handle exception
            msg.setStatus(false);
            msg.setInformation("系统繁忙,请稍后重试!");
        }
        return msg;
		
    }
}
	

 

你可能感兴趣的:(mybatis框架)