大家好,又见面了,我是你们的朋友全栈君。
package com.chj.cms.controller;
import java.util.HashMap; import java.util.Map;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;
import com.chj.cms.domain.Users;
@Controller @RequestMapping(“/admin”) public class TestController {
代码语言:javascript复制@Autowired
private KafkaTemplate<Integer, String> kafkaTemplate;
@RequestMapping("/saveLiuyan")
@ResponseBody
public Map<String,Boolean> save(HttpServletRequest request,Integer fid,String content) {
Map<String,Boolean> map = new HashMap<>();
//留言
Users user = (Users)request.getSession().getAttribute("user");
Integer uid = user.getId();
String message=uid "," fid "," content;
kafkaTemplate.sendDefault(message);
map.put("flag", true);
return map ;
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/133450.html原文链接:https://javaforall.cn