1. ##定义初始变量
    2. #set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
    3. ##设置回调
    4. $!callback.setFileName($tool.append($tableName, ".java"))
    5. $!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
    6. ##拿到主键
    7. #if(!$tableInfo.pkColumn.isEmpty())
    8. #set($pk = $tableInfo.pkColumn.get(0))
    9. #end
    10. #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;
    11. import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
    12. import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
    13. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    14. import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
    15. import lombok.extern.slf4j.Slf4j;
    16. import org.springframework.stereotype.Service;
    17. import javax.annotation.Resource;
    18. /**
    19. * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
    20. *
    21. * @author $!author
    22. * @since $!time.currTime()
    23. */
    24. @Service("$!tool.firstLowerCase($!{tableInfo.name})Service")
    25. @Slf4j
    26. public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service{
    27. @Resource
    28. private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;
    29. /**
    30. * 通过ID查询单条数据
    31. *
    32. * @param $!pk.name 主键
    33. * @return 实例对象
    34. */
    35. @Override
    36. public $!{tableInfo.name} queryById($!pk.shortType $!pk.name) {
    37. return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.queryById($!pk.name);
    38. }
    39. /**
    40. * 新增数据
    41. *
    42. * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
    43. * @return 实例对象
    44. */
    45. @Override
    46. public $!{tableInfo.name} insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
    47. this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert($!tool.firstLowerCase($!{tableInfo.name}));
    48. return $!tool.firstLowerCase($!{tableInfo.name});
    49. }
    50. /**
    51. * 修改数据
    52. *
    53. * @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
    54. * @return 实例对象
    55. */
    56. @Override
    57. public $!{tableInfo.name} update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
    58. this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update($!tool.firstLowerCase($!{tableInfo.name}));
    59. return this.queryById($!{tool.firstLowerCase($!{tableInfo.name})}.get$!tool.firstUpperCase($pk.name)());
    60. }
    61. /**
    62. * 通过主键删除数据
    63. *
    64. * @param $!pk.name 主键
    65. * @return 是否成功
    66. */
    67. @Override
    68. public boolean deleteById($!pk.shortType $!pk.name) {
    69. return this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById($!pk.name) > 0;
    70. }
    71. }