Commit 2c0696aa authored by taabe's avatar taabe

maven import mybatis-spring-boot-starter

parent d99ad5d9
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);
}
}
}
......@@ -2,9 +2,11 @@ package org.amos.boot.biz.common.utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;import java.util.Map;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
......@@ -14,7 +16,7 @@ import java.util.concurrent.TimeUnit;
@Component
public class RedisUtils {
@Autowired
private RedisTemplate<String, Object> redisTemplate;
private RedisTemplate redisTemplate;
/**
* 指定缓存失效时间
......@@ -377,7 +379,6 @@ public class RedisUtils {
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, Object value) {
......@@ -406,7 +407,6 @@ public class RedisUtils {
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public boolean lSet(String key, List<Object> value) {
......@@ -442,6 +442,4 @@ public class RedisUtils {
redisTemplate.opsForList().set(key, index, value);
return true;
}
}
......@@ -3,6 +3,8 @@ 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.utils.CommonResponseUtil;
import org.amos.boot.module.tzs.biz.dao.mapper.TestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -17,10 +19,13 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
@RequestMapping("/test")
public class TestController extends BaseController {
@Autowired
TestMapper testMapper;
@ApiOperation(value = "测试接口")
@GetMapping(value = "/testGet")
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
public ResponseModel test() {
return CommonResponseUtil.success();
return CommonResponseUtil.success(testMapper.countById());
}
}
package org.amos.boot.module.tzs.biz.dao.mapper;
import org.amos.boot.biz.common.dao.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
/**
* @author DELL
*/
public interface TestMapper extends BaseMapper {
/**
* 统计
* @return
*/
@Select(value = "select count(*) from f_dict")
long countById();
}
......@@ -37,7 +37,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@MapperScan({"org.typroject.tyboot.demo.face.orm.dao*",
"org.typroject.tyboot.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*",
"org.amos.boot.module.tzs.biz.dao.mapper"})
@ComponentScan(basePackages = { "org.amos.boot", "org.typroject", "com.yeejoin.amos" })
public class AmosTzsApplication {
private static final Logger logger = LoggerFactory.getLogger(AmosTzsApplication.class);
......
#DB properties:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://172.16.10.66:3306/safety-business-3.0.0?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root_123
\ No newline at end of file
spring.datasource.password=root_123
#eureka properties:
eureka.instance.hostname=172.16.10.72
eureka.instance.prefer-ip-address=true
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:10001/eureka/
......@@ -459,14 +459,9 @@
</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>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
......
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