diff --git a/blogserver/src/main/java/org/sang/service/CategoryService.java b/blogserver/src/main/java/org/sang/service/CategoryService.java new file mode 100644 index 0000000..d7ce692 --- /dev/null +++ b/blogserver/src/main/java/org/sang/service/CategoryService.java @@ -0,0 +1,37 @@ +package org.sang.service; + +import org.sang.bean.Category; +import org.sang.mapper.CategoryMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.sql.Timestamp; +import java.util.List; + + +@Service +@Transactional +public class CategoryService { + @Autowired + CategoryMapper categoryMapper; + + public List getAllCategories() { + return categoryMapper.getAllCategories(); + } + + public boolean deleteCategoryByIds(String ids) { + String[] split = ids.split(","); + int result = categoryMapper.deleteCategoryByIds(split); + return result == split.length; + } + + public int updateCategoryById(Category category) { + return categoryMapper.updateCategoryById(category); + } + + public int addCategory(Category category) { + category.setDate(new Timestamp(System.currentTimeMillis())); + return categoryMapper.addCategory(category); + } +}