2021
02-20
02-20
Springboot+Netty+Websocket实现消息推送实例
前言WebSocket使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动向客户端推送数据。在WebSocketAPI中,浏览器和服务器只需要完成一次握手,两者之间就直接可以创建持久性的连接,并进行双向数据传输。Netty框架的优势 1.API使用简单,开发门槛低; 2.功能强大,预置了多种编解码功能,支持多种主流协议; 3.定制能力强,可以通过ChannelHandler对通信框架进行灵活地扩展; 4.性能高,通...
继续阅读 >
一、关于跨域介绍在前后分离的架构下,跨域问题难免会遇见比如,站点http://domain-a.com的某HTML页面通过的src请求http://domain-b.com/image.jpg。网络上的许多页面都会加载来自不同域的CSS样式表,图像和脚本等资源。出于安全原因,浏览器限制从脚本内发起的跨源HTTP请求。例如,XMLHttpRequest和FetchAPI遵循同源策略。这意味着使用这些API的Web应用程序只能从加载应用程序的同一个域请求HTTP资源,除非使用CORS头文...
1、使用JPA的@Enumerated注解,可以直接将Enum映射到数据库中。但是value的值只有两种方式选择,一种是使用枚举的序号映射,一种是枚举的名称来映射。publicenumEnumType{/**Persistenumeratedtypepropertyorfieldasaninteger.*/ORDINAL,/**Persistenumeratedtypepropertyorfieldasastring.*/STRING}如果想存入枚举中的自定义的值,则需要实现AttributeConverter接口2、实现AttributeConverter接口...
使用内置服务器启动springboot项目时,会从@SpringBootApplication修饰类所在的包开始,加载当前包和所有子包下的类,将由@Component@Repository@Service@Controller修饰的类交由spring进行管理。packagecom.facade;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.context.ConfigurableApplicationContext;importorg.s...
方式一:在所有mapper接口使用@Mapper注解@Mapper(将包中的所有接口都标注为DAO层接口)publicinterfaceUserMapper{UserInfogetUserInfo(@Param("userId")StringuserId);}方式二:在springboot的启动类使用@MapperScan注解(作用:将指定包中的所有接口都标注为DAO层接口,相当于在每一个接口上写@Mapper)@SpringBootApplication@MapperScan(basePackages="com.xiami.springboot.sbootdemo.mapper")publicclassSbootd...
1:默认扫描启动类所在路径下所有的bean2:可以在启动类中添加注解,手动指定扫描路径:@ComponentScan(basePackages={"com.xxx.service1.*","com.xxx.service2.**"})补充:SpringBoot是如何通过@SpringBootApplication扫描项目中的Bean原因首先因为XXXXXXXApplication附带@SpringBootApplication注解,而@SpringBootApplication注解的层次如下:SpringBootApplication----@Inherited----@SpringBootConfiguration--------...
1、springboot启动类实现接口ApplicationListener<ContextRefreshedEvent>,实现方法onApplicationEvent,初始化上下文packagetest.projectTest;importorg.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;importorg.springframework.boot.autoconfigure.SpringBootApplication;import...