Bladeren bron

测试完成

master
liuchao 4 jaren geleden
bovenliggende
commit
64505b965e
  1. 48
      src/main/java/com/ceis/convert/controller/IndexController.java
  2. 4
      src/main/java/com/ceis/convert/entity/mssql/User.java
  3. 14
      src/main/java/com/ceis/convert/entity/mysql/Admin.java
  4. 18
      src/main/java/com/ceis/convert/entity/mysql/User.java
  5. 4
      src/main/java/com/ceis/convert/repository/mssql/MsUserDao.java
  6. 7
      src/main/java/com/ceis/convert/repository/mysql/AdminDao.java
  7. 9
      src/main/java/com/ceis/convert/repository/mysql/MyUserDao.java
  8. 26
      src/main/java/com/ceis/convert/service/MssqlUserService.java
  9. 25
      src/main/java/com/ceis/convert/service/MysqlUserService.java

48
src/main/java/com/ceis/convert/controller/IndexController.java

@ -0,0 +1,48 @@
package com.ceis.convert.controller;
import com.ceis.convert.entity.mssql.User;
import com.ceis.convert.service.MssqlUserService;
import com.ceis.convert.service.MysqlUserService;
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;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.List;
@RestController
public class IndexController {
@Autowired
private MssqlUserService mssqlUserService;
@Autowired
private MysqlUserService mysqlUserService;
@GetMapping("mssql/user")
public Flux<List<User>> getMsUser(){
List<User> list= mssqlUserService.findAll();
return Flux.just(list);
}
@GetMapping("mysql/user")
public Flux<List<com.ceis.convert.entity.mysql.User>> getMyUser(){
List<com.ceis.convert.entity.mysql.User> list= mysqlUserService.findAll();
return Flux.just(list);
}
@GetMapping("mssql/save")
public Mono<User> saveMsUser(){
User user = mssqlUserService.save("nelson mssql");
return Mono.just(user);
}
@GetMapping("mysql/save")
public Mono<com.ceis.convert.entity.mysql.User> saveMyUser(){
com.ceis.convert.entity.mysql.User user = mysqlUserService.save("nelson mysql");
return Mono.just(user);
}
}

4
src/main/java/com/ceis/convert/entity/mssql/User.java

@ -1,7 +1,9 @@
package com.ceis.convert.entity.mssql;
import com.ceis.convert.entity.IDEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.Table;
@ -9,6 +11,8 @@ import javax.persistence.Table;
@Data
@Entity
@Table(name = "tb_user")
@AllArgsConstructor
@NoArgsConstructor
public class User extends IDEntity {
private String userName;
}

14
src/main/java/com/ceis/convert/entity/mysql/Admin.java

@ -1,14 +0,0 @@
package com.ceis.convert.entity.mysql;
import com.ceis.convert.entity.IDEntity;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "tb_admin")
public class Admin extends IDEntity {
private String adminName;
}

18
src/main/java/com/ceis/convert/entity/mysql/User.java

@ -0,0 +1,18 @@
package com.ceis.convert.entity.mysql;
import com.ceis.convert.entity.IDEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.Table;
@Data
@Entity
@Table(name = "tb_user")
@AllArgsConstructor
@NoArgsConstructor
public class User extends IDEntity {
private String userName;
}

4
src/main/java/com/ceis/convert/repository/mssql/UserDao.java → src/main/java/com/ceis/convert/repository/mssql/MsUserDao.java

@ -2,6 +2,8 @@ package com.ceis.convert.repository.mssql;
import com.ceis.convert.entity.mssql.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
public interface UserDao extends JpaRepository<User, Integer>{
@Repository
public interface MsUserDao extends JpaRepository<User, Integer>{
}

7
src/main/java/com/ceis/convert/repository/mysql/AdminDao.java

@ -1,7 +0,0 @@
package com.ceis.convert.repository.mysql;
import com.ceis.convert.entity.mysql.Admin;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AdminDao extends JpaRepository<Admin, Integer> {
}

9
src/main/java/com/ceis/convert/repository/mysql/MyUserDao.java

@ -0,0 +1,9 @@
package com.ceis.convert.repository.mysql;
import com.ceis.convert.entity.mysql.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface MyUserDao extends JpaRepository<User, Integer> {
}

26
src/main/java/com/ceis/convert/service/MssqlUserService.java

@ -0,0 +1,26 @@
package com.ceis.convert.service;
import com.ceis.convert.entity.mssql.User;
import com.ceis.convert.repository.mssql.MsUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class MssqlUserService {
@Autowired
private MsUserDao userDao;
public List<User> findAll() {
return userDao.findAll();
}
public User save(String name) {
User user = new User(name);
return userDao.saveAndFlush(user);
}
}

25
src/main/java/com/ceis/convert/service/MysqlUserService.java

@ -0,0 +1,25 @@
package com.ceis.convert.service;
import com.ceis.convert.entity.mysql.User;
import com.ceis.convert.repository.mysql.MyUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class MysqlUserService {
@Autowired
private MyUserDao userDao;
public List<User> findAll() {
return userDao.findAll();
}
public User save(String name) {
User user = new User(name);
return userDao.saveAndFlush(user);
}
}
Laden…
Annuleren
Opslaan