liuchao
4年前
9個のファイルの変更、133行の追加、22行の削除
@ -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); |
|||
} |
|||
} |
@ -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; |
|||
} |
@ -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; |
|||
} |
@ -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> { |
|||
} |
@ -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> { |
|||
} |
@ -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); |
|||
} |
|||
} |
@ -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); |
|||
} |
|||
} |
読み込み中…
新しい課題から参照