首页>代码>基于html5的websocket后台即时通讯,三个小例子,从简单到复杂,从无界面到有界面>/websocket-demo/src/main/java/com/example/demo/controller/TestController.java
package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * websocket接口测试模拟
 * @author 程就人生
 * @date 2019年9月24日
 */
@RestController
public class TestController {
	
	/**
	 * 最简易的
	 * @return
	 */
	@GetMapping("/index")
	public ModelAndView index(){
		return new ModelAndView("/index1");
	}
	
	/**
	 * 模拟聊天,可以看见收发信息
	 * @param userUid
	 * @return
	 */
	@GetMapping("/index2/{userUid}")
	public ModelAndView index2(@PathVariable("userUid") String userUid){
		ModelAndView mv = new ModelAndView("/index2");		
		mv.addObject("userUid", userUid);
		return mv;
	}
	
	/**
	 * 较为复杂的,有窗口样式
	 * @param userUid
	 * @return
	 */
	@GetMapping("/index3/{userUid}") 
	public ModelAndView socket(@PathVariable("userUid") String userUid) { 
		ModelAndView mv = new ModelAndView("/index3");
		String userLogo = "icon01.png";
		if(userUid.equals("2")){
			userLogo = "icon02.png";
	    }else if(userUid.equals("3")){
	    	userLogo = "icon03.png";
	    }
		mv.addObject("userUid", userUid);
		mv.addObject("userLogo", userLogo);
		return mv;
	}
}
最近下载更多
荣》Cowboy  LV12 2023年3月29日
zz1230012300  LV11 2022年8月22日
wang512237140  LV20 2022年8月2日
无花空折枝  LV9 2022年8月1日
a1677596408  LV23 2021年7月27日
xxxxx2021  LV1 2021年7月14日
1666568158  LV2 2021年5月18日
1517536943  LV5 2021年4月25日
johnlhr  LV4 2020年10月25日
930384782  LV9 2020年9月30日
最近浏览更多
13940562934  LV22 3月6日
1234567p  LV1 2023年12月4日
漫步的海星  LV4 2023年9月21日
shaoqi 2023年7月26日
暂无贡献等级
荣》Cowboy  LV12 2023年3月29日
lijiecai  LV2 2023年3月18日
微信网友_6393440821071872  LV2 2023年3月17日
dagf113225  LV68 2023年2月7日
xiexiaoming05  LV14 2023年1月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友