Commit 9f24b314 authored by taabe's avatar taabe

common包添加mybatis BaseMapper,jpa BaseDao, BaseEntity

parent 8e9a7d62
package org.amos.boot.biz.common.configs;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* swagger配置类 模块如果需要引入则引入
*
* @author DELL
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("服务接口")
.enable(true)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.apis(RequestHandlerSelectors.basePackage("org.amos.boot"))
.paths(PathSelectors.any())
.build();
}
/**
* 构建 api文档的详细信息函数,注意这里的注解引用的是哪个
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("RestFul API")
//创建人
.contact(new Contact("amos", "", ""))
//版本号
.version("1.0")
//描述
.description("API 描述")
.build();
}
}
\ No newline at end of file
package org.amos.boot.biz.common.dao.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* MyBatis BaseMapper
* @author DELL
*/
@Mapper
public interface BaseMapper {
}
package org.amos.boot.biz.common.dao.repository;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.io.Serializable;
import java.util.List;
/**
* 基础dao
*
* @author DELL
* @param <T>
* @param <ID>
*/
@NoRepositoryBean
public interface BaseDao<T, ID extends Serializable> extends JpaRepository<T, ID>, CrudRepository<T, ID>,
PagingAndSortingRepository<T, ID>, JpaSpecificationExecutor<T> {
/**
* 查询
* @param specification
* @return
*/
public default T getOneBySpecification(Specification<T> specification) {
List<T> list = findAll(specification);
if (list.isEmpty()) {
return null;
} else {
return list.get(0);
}
}
}
package org.amos.boot.biz.common.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 公共实体类
*
* @author DELL
*/
@Data
public class BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 唯一主键
*/
@TableId(type = IdType.ID_WORKER)
private Long id;
/**
* 创建时间
*/
@TableField(value = "create_date", fill = FieldFill.INSERT)
private Date createDate;
/**
* 更新时间
*/
@TableField(value = "update_date", fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
}
...@@ -13,6 +13,7 @@ import java.util.concurrent.TimeUnit; ...@@ -13,6 +13,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* @author DELL * @author DELL
*/ */
@Component
public class RedisUtils { public class RedisUtils {
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
......
package org.amos.boot.module.tzs.biz.controller; package org.amos.boot.module.tzs.biz.controller;
import io.swagger.annotations.ApiOperation;
import org.amos.boot.biz.common.controller.BaseController; import org.amos.boot.biz.common.controller.BaseController;
import org.amos.boot.biz.common.utils.CommonResponseUtil; import org.amos.boot.biz.common.utils.CommonResponseUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
/**
* @author DELL
*/
@RestController @RestController
@RequestMapping("/test") @RequestMapping("/test")
public class TestController extends BaseController { public class TestController extends BaseController {
@ApiOperation(value = "测试接口")
@GetMapping(value = "/testGet")
public ResponseModel test() { public ResponseModel test() {
return CommonResponseUtil.success(); return CommonResponseUtil.success();
} }
......
...@@ -25,7 +25,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -25,7 +25,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
* *
* @author DELL * @author DELL
*/ */
@SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
@EnableConfigurationProperties @EnableConfigurationProperties
@EnableSwagger2 @EnableSwagger2
...@@ -38,7 +38,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -38,7 +38,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
"org.typroject.tyboot.face.*.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*", "org.typroject.tyboot.core.auth.face.orm.dao*",
"org.typroject.tyboot.component.*.face.orm.dao*"}) "org.typroject.tyboot.component.*.face.orm.dao*"})
@SpringBootApplication(scanBasePackages = {"com.yeejoin.amos","org.typroject"}) @ComponentScan(basePackages = { "org.amos.boot", "org.typroject", "com.yeejoin.amos" })
public class AmosTzsApplication { public class AmosTzsApplication {
private static final Logger logger = LoggerFactory.getLogger(AmosTzsApplication.class); private static final Logger logger = LoggerFactory.getLogger(AmosTzsApplication.class);
...@@ -51,6 +51,7 @@ public class AmosTzsApplication { ...@@ -51,6 +51,7 @@ public class AmosTzsApplication {
+ " has already been started in " + " has already been started in "
+ environment.getProperty("spring.profiles.active") + "" + environment.getProperty("spring.profiles.active") + ""
+ " environment,and service's url is 'http://localhost:" + " environment,and service's url is 'http://localhost:"
+ environment.getProperty("server.port") + "/swagger-ui.html'"); + environment.getProperty("server.port")
+ environment.getProperty("server.servlet.context-path") + "/swagger-ui.html'");
} }
} }
...@@ -457,6 +457,17 @@ ...@@ -457,6 +457,17 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment