Seata 整合学习完成
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.test;
|
||||
|
||||
import com.apple.eawt.Application;
|
||||
import io.seata.spring.annotation.datasource.EnableAutoDataSourceProxy;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@@ -11,6 +12,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
* @author yovinchen
|
||||
* @Create 2023/8/14 16:23
|
||||
*/
|
||||
@EnableAutoDataSourceProxy
|
||||
@SpringBootApplication
|
||||
public class BookApplication {
|
||||
public static void main(String[] args) {
|
||||
|
@@ -26,4 +26,15 @@ public class BookController {
|
||||
System.out.println("调用图书服务");
|
||||
return service.getBookById(bid);
|
||||
}
|
||||
|
||||
@RequestMapping("/book/remain/{bid}")
|
||||
public int bookRemain(@PathVariable("bid") int uid){
|
||||
return service.getRemain(uid);
|
||||
}
|
||||
|
||||
@RequestMapping("/book/borrow/{bid}")
|
||||
public boolean bookBorrow(@PathVariable("bid") int uid){
|
||||
int remain = service.getRemain(uid);
|
||||
return service.setRemain(uid, remain - 1);
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package com.test.mapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import com.test.entity.Book;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* ClassName: BookMapper
|
||||
@@ -16,4 +17,10 @@ public interface BookMapper {
|
||||
|
||||
@Select("select * from DB_BOOK where bid = #{bid}")
|
||||
Book getBookById(int bid);
|
||||
|
||||
@Select("select count from DB_BOOK where bid = #{bid}")
|
||||
int getRemain(int bid);
|
||||
|
||||
@Update("update DB_BOOK set count = #{count} where bid = #{bid}")
|
||||
int setRemain(int bid, int count);
|
||||
}
|
||||
|
@@ -11,4 +11,10 @@ import com.test.entity.Book;
|
||||
*/
|
||||
public interface BookService {
|
||||
Book getBookById(int bid);
|
||||
|
||||
boolean setRemain(int uid, int i);
|
||||
|
||||
int getRemain(int uid);
|
||||
|
||||
|
||||
}
|
||||
|
@@ -24,4 +24,14 @@ public class BookServiceImpl implements BookService {
|
||||
public Book getBookById(int bid) {
|
||||
return mapper.getBookById(bid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setRemain(int bid, int count) {
|
||||
return mapper.setRemain(bid, count) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRemain(int bid) {
|
||||
return mapper.getRemain(bid);
|
||||
}
|
||||
}
|
||||
|
@@ -14,8 +14,20 @@ spring:
|
||||
discovery:
|
||||
# 配置Nacos注册中心地址
|
||||
server-addr: localhost:8848
|
||||
namespace: dd668135-0bfe-489f-ab2b-24aefb21d156
|
||||
sentinel:
|
||||
transport:
|
||||
# 添加监控页面地址即可
|
||||
dashboard: localhost:8858
|
||||
seata:
|
||||
# 注册
|
||||
registry:
|
||||
# 使用Nacos
|
||||
type: nacos
|
||||
nacos:
|
||||
# 使用Seata的命名空间,这样才能正确找到Seata服务,由于组使用的是SEATA_GROUP,配置默认值就是,就不用配了
|
||||
namespace: c0495138-b5b3-440d-8f1c-dc8cc9ba5fbc
|
||||
username: nacos
|
||||
password: nacos
|
||||
# 配置
|
||||
config:
|
||||
type: nacos
|
||||
nacos:
|
||||
namespace: c0495138-b5b3-440d-8f1c-dc8cc9ba5fbc
|
||||
username: nacos
|
||||
password: nacos
|
||||
|
Reference in New Issue
Block a user