listUser();
19 |
20 | User selectUserById(final Integer id);
21 |
22 | void delete(final Integer id);
23 |
24 | void update(final User user);
25 | }
26 |
--------------------------------------------------------------------------------
/springboot-transactional/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | #设置应用端口
2 | server:
3 | port: 8080
4 |
5 | spring:
6 | datasource:
7 | driver-class-name: com.mysql.cj.jdbc.Driver
8 | url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
9 | username: root
10 | password: root
11 |
12 | # MyBatis
13 | mybatis:
14 | type-aliases-package: com.example.springboottransactional.domain
15 | mapper-locations: classpath:/mybatis/*.xml
16 | #sql打印配置
17 | configuration:
18 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
19 |
--------------------------------------------------------------------------------
/springboot-transactional/src/main/resources/mybatis/userMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
19 |
20 |
21 | update user set user_name = #{userName} where user_id = #{userId}
22 |
23 |
24 |
25 | delete from user where user_id = #{id}
26 |
27 |
28 |
--------------------------------------------------------------------------------
/springboot-transactional/src/test/java/com/example/springboottransactional/SpringbootTransactionalApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.springboottransactional;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootTransactionalApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-webservice/.gitignore:
--------------------------------------------------------------------------------
1 | ######################################################################
2 | # Build Tools
3 |
4 | .gradle
5 | /build/
6 | !gradle/wrapper/gradle-wrapper.jar
7 |
8 | target/
9 | !.mvn/wrapper/maven-wrapper.jar
10 |
11 | ######################################################################
12 | # IDE
13 |
14 | ### STS ###
15 | .apt_generated
16 | .classpath
17 | .factorypath
18 | .project
19 | .settings
20 | .springBeans
21 |
22 | ### IntelliJ IDEA ###
23 | .idea
24 | *.iws
25 | *.iml
26 | *.ipr
27 |
28 | ### NetBeans ###
29 | nbproject/private/
30 | build/*
31 | nbbuild/
32 | dist/
33 | nbdist/
34 | .nb-gradle/
35 |
36 | ######################################################################
37 | # Others
38 | *.log
39 | *.xml.versionsBackup
40 |
41 | !*/build/*.java
42 | !*/build/*.html
43 | !*/build/*.xml
44 |
--------------------------------------------------------------------------------
/springboot-webservice/src/main/java/com/example/springbootwebservice/SpringbootWebserviceApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebservice;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringbootWebserviceApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringbootWebserviceApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-webservice/src/main/java/com/example/springbootwebservice/config/WSConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebservice.config;
2 |
3 | import com.example.springbootwebservice.config.client.WsClient;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller;
7 |
8 | @Configuration
9 | public class WSConfig {
10 |
11 | @Bean
12 | public Jaxb2Marshaller marshaller() {
13 |
14 | Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
15 | marshaller.setContextPath("com.example.springbootwebservice.domain");
16 | return marshaller;
17 | }
18 |
19 | @Bean
20 | public WsClient wsClient(Jaxb2Marshaller marshaller) {
21 |
22 | WsClient client = new WsClient();
23 | client.setDefaultUri("http://127.0.0.1:8080/ws/countries.wsdl");
24 | client.setMarshaller(marshaller);
25 | client.setUnmarshaller(marshaller);
26 |
27 | return client;
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/springboot-webservice/src/main/java/com/example/springbootwebservice/config/client/WsClient.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebservice.config.client;
2 |
3 | import com.example.springbootwebservice.domain.GetCountryRequest;
4 | import com.example.springbootwebservice.domain.GetCountryResponse;
5 | import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
6 |
7 | public class WsClient extends WebServiceGatewaySupport {
8 |
9 | public GetCountryResponse getCountry(String name) {
10 |
11 | GetCountryRequest request = new GetCountryRequest();
12 | request.setName(name);
13 | //连接服务端
14 | GetCountryResponse response = (GetCountryResponse) getWebServiceTemplate()
15 | .marshalSendAndReceive(
16 | "http://127.0.0.1:8080/ws/countries.wsdl",
17 | request);
18 |
19 | return response;
20 | }
21 | }
--------------------------------------------------------------------------------
/springboot-webservice/src/main/java/com/example/springbootwebservice/controller/IndexController.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebservice.controller;
2 |
3 | import com.example.springbootwebservice.config.client.WsClient;
4 | import com.example.springbootwebservice.domain.GetCountryResponse;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | @RestController
10 | public class IndexController {
11 |
12 | @Autowired
13 | private WsClient wsClient;
14 |
15 | @RequestMapping("getCountry")
16 | public Object getCountry(String name) {
17 | GetCountryResponse response = wsClient.getCountry(name);
18 |
19 | return response.getCountry();
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/springboot-webservice/src/main/java/com/example/springbootwebservice/domain/Currency.java:
--------------------------------------------------------------------------------
1 |
2 | package com.example.springbootwebservice.domain;
3 |
4 | import javax.xml.bind.annotation.XmlEnum;
5 | import javax.xml.bind.annotation.XmlType;
6 |
7 |
8 | /**
9 | * currency�� Java �ࡣ
10 | *
11 | *
����ģʽƬ��ָ�������ڴ����е�Ԥ�����ݡ�
12 | *
13 | *
14 | * <simpleType name="currency">
15 | * <restriction base="{http://www.w3.org/2001/XMLSchema}string">
16 | * <enumeration value="GBP"/>
17 | * <enumeration value="EUR"/>
18 | * <enumeration value="PLN"/>
19 | * </restriction>
20 | * </simpleType>
21 | *
22 | */
23 | @XmlType(name = "currency", namespace = "http://127.0.0.1:8080/ws")
24 | @XmlEnum
25 | public enum Currency {
26 |
27 | GBP,
28 | EUR,
29 | PLN;
30 |
31 | public String value() {
32 | return name();
33 | }
34 |
35 | public static Currency fromValue(String v) {
36 | return valueOf(v);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/springboot-webservice/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/springboot-webservice/src/test/java/com/example/springbootwebservice/SpringbootWebserviceApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebservice;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootWebserviceApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/springboot-websocket/.gitignore:
--------------------------------------------------------------------------------
1 | ######################################################################
2 | # Build Tools
3 |
4 | .gradle
5 | /build/
6 | !gradle/wrapper/gradle-wrapper.jar
7 |
8 | target/
9 | !.mvn/wrapper/maven-wrapper.jar
10 |
11 | ######################################################################
12 | # IDE
13 |
14 | ### STS ###
15 | .apt_generated
16 | .classpath
17 | .factorypath
18 | .project
19 | .settings
20 | .springBeans
21 |
22 | ### IntelliJ IDEA ###
23 | .idea
24 | *.iws
25 | *.iml
26 | *.ipr
27 |
28 | ### NetBeans ###
29 | nbproject/private/
30 | build/*
31 | nbbuild/
32 | dist/
33 | nbdist/
34 | .nb-gradle/
35 |
36 | ######################################################################
37 | # Others
38 | *.log
39 | *.xml.versionsBackup
40 |
41 | !*/build/*.java
42 | !*/build/*.html
43 | !*/build/*.xml
44 |
--------------------------------------------------------------------------------
/springboot-websocket/README.md:
--------------------------------------------------------------------------------
1 | # springboot集成websocket
2 |
3 | ## pom依赖引入
4 |
5 |
6 |
--------------------------------------------------------------------------------
/springboot-websocket/src/main/java/com/example/springbootwebsocket/ServletInitializer.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebsocket;
2 |
3 | import org.springframework.boot.builder.SpringApplicationBuilder;
4 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
5 |
6 | public class ServletInitializer extends SpringBootServletInitializer {
7 |
8 | @Override
9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
10 | return application.sources(SpringbootWebsocketApplication.class);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-websocket/src/main/java/com/example/springbootwebsocket/SpringbootWebsocketApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebsocket;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringbootWebsocketApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringbootWebsocketApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/springboot-websocket/src/main/java/com/example/springbootwebsocket/config/WebSocketConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebsocket.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.web.socket.server.standard.ServerEndpointExporter;
6 |
7 | /**
8 | * 开启WebSocket支持
9 | */
10 | @Configuration
11 | public class WebSocketConfig {
12 |
13 | @Bean
14 | public ServerEndpointExporter serverEndpointExporter() {
15 | return new ServerEndpointExporter();
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/springboot-websocket/src/main/java/com/example/springbootwebsocket/server/BaseController.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebsocket.server;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.example.springbootwebsocket.domain.Message;
5 | import com.example.springbootwebsocket.utils.StringUtil;
6 |
7 | /**
8 | * 公共逻辑
9 | */
10 | public abstract class BaseController extends AbstractWsController {
11 |
12 | private static final String CONNECT_TYPE_TEXT = "text";
13 |
14 | /**
15 | * 接受客户端发送的字符串
16 | *
17 | * @param message 字符串消息
18 | */
19 | @Override
20 | protected void onMessage(String message) {
21 | Message msg = JSONObject.parseObject(message, Message.class);
22 | msg.setHost(getUserName());
23 | if (CONNECT_TYPE_TEXT.equals(getConnectType())) {
24 | msg.setMsg(StringUtil.txt2htm(msg.getMsg()));
25 | if (msg.getDests() == null) {
26 | broadcast2All(msg.toString());
27 | } else {
28 | broadcast2Special(msg.toString(), msg.getDests());
29 | }
30 | } else {
31 | broadcast2Others(msg.toString());
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/springboot-websocket/src/main/java/com/example/springbootwebsocket/server/BaseMediaController.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebsocket.server;
2 |
3 | import javax.websocket.EndpointConfig;
4 | import javax.websocket.Session;
5 | import java.io.IOException;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | /**
10 | * 公共逻辑
11 | */
12 | public abstract class BaseMediaController extends BaseController {
13 |
14 | @Override
15 | public void onOpen(Session session, EndpointConfig config) {
16 | // 设置用户信息
17 | Map> map = session.getRequestParameterMap();
18 | setSession(session);
19 | List uids = map.get("uid");
20 | if (uids == null) {
21 | try {
22 | this.getSession().close();
23 | } catch (IOException ignored) {
24 | }
25 | } else {
26 | setUserName(uids.get(0));
27 | super.onOpen(session, config);
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/springboot-websocket/src/main/java/com/example/springbootwebsocket/utils/IdGenerator.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebsocket.utils;
2 |
3 | import java.util.concurrent.locks.Lock;
4 | import java.util.concurrent.locks.ReentrantLock;
5 |
6 | /**
7 | * 获取随机id (时间戳 + 服务器id + 2位数字序号)
8 | *
9 | */
10 | public class IdGenerator {
11 |
12 | private static int SERVER_ID = 0;
13 | private static final long LIMIT = 10;
14 | private static final Lock LOCK = new ReentrantLock();
15 | private static long LastTime = System.currentTimeMillis();
16 | private static int COUNT = 0;
17 |
18 | public static String getNextId() {
19 | LOCK.lock();
20 | try {
21 | while (true) {
22 | long now = System.currentTimeMillis();
23 | if (now == LastTime) {
24 | if (++COUNT == LIMIT) {
25 | try {
26 | Thread.currentThread();
27 | Thread.sleep(1);
28 | } catch (InterruptedException ignored) {
29 | }
30 | continue;
31 | }
32 | } else {
33 | LastTime = now;
34 | COUNT = 0;
35 | }
36 | break;
37 | }
38 | } finally {
39 | LOCK.unlock();
40 | }
41 |
42 | return String.format("%d%d%02d", LastTime, SERVER_ID, COUNT);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 | spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
3 | spring.datasource.url = jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
4 | spring.datasource.username = root
5 | spring.datasource.password = xxx
6 |
7 | spring.thymeleaf.cache=false
8 | spring.thymeleaf.prefix=classpath:/templates/
9 | spring.thymeleaf.check-template-location=true
10 | spring.thymeleaf.suffix=.html
11 | spring.thymeleaf.encoding=UTF-8
12 | spring.thymeleaf.servlet.content-type=text/html
13 | spring.thymeleaf.mode=HTML5
14 |
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/Toolbar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/Toolbar.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/btn_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/btn_close.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/btn_close_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/btn_close_down.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/btn_close_hover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/btn_close_hover.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/canvaspost.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/canvaspost.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/headpic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/headpic.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/mod_chat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/mod_chat.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/mod_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/mod_file.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/mod_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/mod_video.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/mod_voice.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/mod_voice.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/photo_loading.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/photo_loading.jpg
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/sprite_main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/sprite_main.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/static/pic/websocket/videopost.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fujiangwei/springboot-learn/a4f23d852609ae1b8887907cc8199baaf5290a0e/springboot-websocket/src/main/resources/static/pic/websocket/videopost.png
--------------------------------------------------------------------------------
/springboot-websocket/src/main/resources/templates/index3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/springboot-websocket/src/test/java/com/example/springbootwebsocket/SpringbootWebsocketApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootwebsocket;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootWebsocketApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------