<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                **1. 在父工程下構建服務端模塊:cloud-provider-dept-8001** ![](https://img.kancloud.cn/6a/12/6a1229901270e4eb564ae1cd6ada7038_1455x141.jpg) ![](https://img.kancloud.cn/2a/24/2a24be50d95876bfab1d27a1a4bd1412_1475x308.jpg) **2. 當前模塊的`pom.xml`** ```xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <!-- 1. 子模塊引入父工程進行統一版本控制 --> <artifactId>rest-cloud-parent</artifactId> <groupId>org.atguigu.springcloud</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>cloud-provider-dept-8001</artifactId> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <!-- 2. 當前子模塊沒有寫版本時,則用父工程中指定的版本--> <dependencies> <!-- 3. 引入自定義的模塊,便可以在當前模塊中調用自定義模塊的API了,就是引入了自己的JAR包 --> <dependency> <groupId>org.atguigu.springcloud</groupId> <artifactId>cloud-api</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>8</source> <target>8</target> </configuration> </plugin> </plugins> </build> </project> ``` **3. 你會在父工程的`pom.xml`中看到引入了當前的模塊** ```xml <modules> <module>cloud-api</module> <module>cloud-provider-dept-8001</module> </modules> ``` **4. 當前模塊用到的resources配置文件如下** (1)*`resources/application.yml`* ```yml server: port: 8001 # 服務訪問端口為8001 mybatis: config-location: classpath:mybatis/mybatis.cfg.xml # mybatis配置文件所在路徑 type-aliases-package: com.atguigu.springcloud.api.entities # 實體類所在的包 mapper-locations: - classpath:mybatis/mapper/**/*.xml # mapper映射文件所在的路徑 spring: application: name: ${project.artifactId} # 該名字非常重要,它是當前模塊對外服務時暴露的名字 datasource: type: com.alibaba.druid.pool.DruidDataSource # 當前數據源操作類型 driver-class-name: com.mysql.jdbc.Driver # mysql驅動包 url: jdbc:mysql://localhost:3306/cloudDB01 # 數據庫地址 username: root password: root dbcp2: min-idle: 5 # 數據庫連接池的最小維持連接數 initial-size: 5 # 初始化連接數 max-total: 5 # 最大連接數 max-wait-millis: 200 # 等待連接獲取的最大超時時間 ``` (2)*`resources/mybatis/mybatis.cfg.xml`* ```xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <!-- 其實mybatis整合到springboot后,mybatis.cfg.xml文件是可以不用的, mybatis的相關配置可以移到application.yml,或application.properties中配置。 --> <configuration> <settings> <setting name="cacheEnabled" value="true"/><!-- 二級緩存開啟 --> </settings> </configuration> ``` **5. 在當前模塊中創建Mybatis的映射文件** *`resources/mybatis/mapper/DeptMapper.xml`* ```xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.atguigu.springcloud.dept8001.dao.DeptDao"> <select id="findById" resultType="Dept" parameterType="Long"> select deptno,dname,db_source from dept where deptno=#{deptno}; </select> <select id="findAll" resultType="Dept"> select deptno,dname,db_source from dept; </select> <insert id="addDept" parameterType="Dept"> INSERT INTO dept(dname,db_source) VALUES(#{dname},DATABASE()); </insert> </mapper> ``` **6. 在當前模塊中創建dao層、service層、controller** (1)dao層 ```java @Component public interface DeptDao { public boolean addDept(Dept dept); public Dept findById(Long id); public List<Dept> findAll(); } ``` (2)service層 ```java public interface DeptService { public boolean add(Dept dept); public Dept get(Long id); public List<Dept> list(); } ``` ```java @Service public class DeptServiceImpl implements DeptService { @Autowired private DeptDao dao; @Override public boolean add(Dept dept) { return dao.addDept(dept); } @Override public Dept get(Long id) { return dao.findById(id); } @Override public List<Dept> list() { return dao.findAll(); } } ``` (3)controller層 ```java @RestController @RequestMapping("/dept") public class DeptController { @Autowired private DeptService service; @RequestMapping(value = "/add", method = RequestMethod.POST) public boolean add(@RequestBody Dept dept) { return service.add(dept); } @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) public Dept get(@PathVariable("id") Long id) { return service.get(id); } @RequestMapping(value = "/list", method = RequestMethod.GET) public List<Dept> list() { return service.list(); } } ``` **7. 當前模塊的啟動類** ```java @SpringBootApplication // 標注該類為啟動類 @MapperScan("com.atguigu.springcloud.dept8001.dao") // 掃描dao層 public class DeptProvider8001App { public static void main(String[] args) { SpringApplication.run(DeptProvider8001App.class, args); } } ``` **8. 驗證** 啟動當前模塊,訪問 http://localhost:8001/dept/list 得出如下結果,則項目構建成功! ```json [{"deptno":1,"dname":"開發部","db_source":"clouddb01"},{"deptno":2,"dname":"人事部","db_source":"clouddb01"},{"deptno":3,"dname":"財務部","db_source":"clouddb01"},{"deptno":4,"dname":"市場部","db_source":"clouddb01"},{"deptno":5,"dname":"運維部","db_source":"clouddb01"}] ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看