19-Spring MVC - Project Work | ContactService Implementation Biz Logic (Contact App)- By eZeon

Опубликовано: 28 Июнь 2026
на канале: Vikram Thakur
4,231
31

This Project Work(Contact App) video is based on Business Logic(Service Implementation) and testing it independently(out of MVC and Without Web Server).

WHAT IS BUSINESS LOGIC OR DOMAIN LOGIC OR SERVICE?
Business Logic is a most important part of the project(backbone) where customer requirement is development along with workflow.

According to wikipedia(https://en.wikipedia.org/wiki/Busines...) :
In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be created, stored, and changed.

WHAT IS BUSINESS LAYER OR SERVICE LAYER?
Service layer contains business logic of the project. There can be multiple service class and interfaces involved to meet the business requirement. It should be independent, portable and loosely coupled with another layer of the project/application.

HOW SERVICE CLASS IS DIFFERENT FROM DAO CLASS?
Service Class contains business logic where different operations can be executed together in a proper order to meet business-requirement. The logic in service class can communicate with other systems like Email Server, FTP Server, SMS API. The logic in service layer can join multiple tables to fetch records or prepare the reports.

DAO Class contains operations/methods to handle CRUD operations for SINGLE ENTITY/TABLE. In practices DAO does not contains table-join operation. But DAO can be reused in Service Layer.

HOW TO DEVELOP BUSINESS LOGIC or SERVICES?
1.Create SERVICE INTERFACE which contains different business methods prototypes with proper documentation.

2.Provide Service Implementation class. This class contains the definition of business methods. The Service Class can reuse DAO classes.It also contains Database Operation, Transaction Handing, Business Flow, Email/SMTP Operations, SMS Operations or anything which is required to client(client-requirement).

3. Finally test the Service independently(out of MVC layer). JUnit can also be used.


COVERAGE IN THIS VIDEO:
1. ContactService Implementation Class(Service Bean) - ContactServiceImpl
2. Testing of ContactService and ContactServiceImpl

CODE REFERENCE:
//ContactServiceImpl.java
package in.ezeon.capp.service;
import in.ezeon.capp.dao.BaseDAO;
import in.ezeon.capp.dao.ContactDAO;
import in.ezeon.capp.domain.Contact;
import in.ezeon.capp.rm.ContactRowMapper;
import in.ezeon.capp.util.StringUtil;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
The class contains implementation of ContactService interface. (business logic for contact entity)
@author Vikram
*/
@Service
public class ContactServiceImpl extends BaseDAO implements ContactService{

@Autowired
private ContactDAO contactDAO;

@Override
public void save(Contact c) {
contactDAO.save(c);
}

@Override
public void update(Contact c) {
contactDAO.update(c);
}

@Override
public void delete(Integer cotactId) {
contactDAO.delete(cotactId);
}

@Override
public void delete(Integer[] cotactIds) {
String ids = StringUtil.toCommaSeparatedString(cotactIds);
String sql = "DELETE FROM contact WHERE contactId IN("+ids+")";
getJdbcTemplate().update(sql);
}

@Override
public List findUserContact(Integer userId) {
return contactDAO.findByProperty("userId", userId);
}

@Override
public List findUserContact(Integer userId, String txt) {
String sql = "SELECT contactId, userId, name, phone, email, address, remark FROM contact WHERE userId=? AND (name LIKE '%"+txt+"%' OR address LIKE '%"+txt+"%' OR phone LIKE '%"+txt+"%' OR email LIKE '%"+txt+"%' OR remark LIKE '%"+txt+"%')";
return getJdbcTemplate().query(sql, new ContactRowMapper(),userId);
}
}

Don't skip or miss any video, just follow step by step video series.
Also check the source code listing in our
blog http://ezeon.in/blog

SUBSCRUBE my channel for more videos on Java Technologies and Software Development including all advanced development frameworks and technologies.