spring cloud 搭建(多JPA,JPA分页)
2021-02-15 16:23
                         标签:sele   native   方法   value   mapping   frame   Pageable   get   cti    随着项目的迭代。 我们在老项目中,把service和dao都放在相同module下,已经不合适了。 service和dao越来越臃肿。如下所示     我们就开始认为每个微服务,都拥有自己的model,dao,service。 而上图的module只是充当基类存在的使用。   这个时候JPA就会变成多个。 那么我们需要如何配置呢?   还是以 https://blog.csdn.net/hanjun0612/article/details/105239557 中service1服务举例。 我们在里面创建 model,dao.service    springboot版本 通过这个指定JPA扫描特定的包! @EnableJpaRepositories(basePackages = "com.test.service1.dao")   @Entity的包:[Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final]    JpaRepository的包:[Maven: org.springframework.data:spring-data-jpa:1.11.13.RELEASE] 方法一:(有警告,但不影响使用)   这里有个警告,但是不影响使用:Parameter with that position [1] did not exist 然后我修改成方法二,就可以了   方法二 /*#pageable*/   作为注释(好奇怪的写法,警告居然就没了。)   service   Impl       spring cloud 搭建(多JPA,JPA分页) 标签:sele   native   方法   value   mapping   frame   Pageable   get   cti    原文地址:https://www.cnblogs.com/hanjun0612/p/12712762.html
正文:

 
一,启动类
@SpringBootApplication
@EnableEurekaClient
@EnableJpaRepositories(basePackages = "com.test.service1.dao")
public class Service1Application {
public static void main(String[] args) {
SpringApplication.run(Service1Application.class, args);
}
}
 二,数据库(只需要id,name)

 三,Model
@Data
@Entity
@Table(name="test",catalog = "testdb")
public class Test {
private Integer id;
private String name;
@Id
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
四,Dao
@Repository
public interface TestDao extends JpaRepository
@Repository
public interface TestDao extends JpaRepository
五,Service
public interface testService {
Page
@Service("testservice")
public class testImpl implements testService {
@Autowired
TestDao testDao;
@Override
public Page
六,Controller
@RestController
@RequestMapping("test")
public class TestController {
@Value("${isDebug}")
private String isDebug;
@Autowired
testService testService;
@GetMapping(value = "/hello")
public String hello(){
return isDebug;
}
//JPA测试
@PostMapping(value="/test")
public Page
七,测试
