上篇:导读认识Flink
框架搭建,如图所示:
父工程构建出来了
接下来,在父工程中创建springboot项目,构建DSInfoservice子模块
并在DSInfoservice子模块,添加引用依赖:
pom.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.study</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>DSInfoservice</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>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>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
1、在DSInfoservice子模块代码编写
(1)编写DsInfoSJservice类
package com.youfan.test;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
*/
@Controller
@RequestMapping("DsInfoSJservice")
public class DsInfoSJservice {
@RequestMapping(value = "webInfoSJservice")
public void webInfoSJservice( String jsonstr, HttpServletRequest request, HttpServletResponse response){
System.out.println("hello Jin 来了!");
}
}
(2)配置全局文件
application.properties
server.port=6097
spring.application.name=DSInfoservice
(3)启动启动类控制台打印与访问:
(4)对DsInfoSJservice类的代码进行完善,如下代码:
package com.youfan.test;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
/**
*
*/
@Controller
@RequestMapping("DsInfoSJservice")
public class DsInfoSJservice {
@RequestMapping(value = "webInfoSJservice", method = RequestMethod.POST)
public void webInfoSJservice(@RequestBody String jsonstr, HttpServletRequest request, HttpServletResponse response) {
System.out.println("hello Jin 来了!");
//业务开始
//业务结束
PrintWriter printWriter = getWriter(response);
printWriter.write("success");
closeprintwriter(printWriter);
}
private PrintWriter getWriter(HttpServletResponse response) {
response.setCharacterEncoding("utf-8");
response.setContentType("application/json");
OutputStream out = null;
PrintWriter printWriter=null;
try {
out = response.getOutputStream();
printWriter = new PrintWriter(out);
} catch (IOException e) {
e.printStackTrace();
}
return printWriter;
}
private void closeprintwriter(PrintWriter printWriter){
printWriter.flush();
printWriter.close();
}
}