package cn.shq.controller; import cn.shq.service.TmmlReqAService; import cn.shq.entity.TmmlReqA; import com.alibaba.fastjson2.JSON; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Objects; import static java.lang.System.out; @Controller @RequestMapping("tmmlReqA") public class TmmlReqAController { @Autowired private TmmlReqAService tmmlReqAService;/* <-----自动注入service对象 ,然后下面可以调用方法*/ @RequestMapping(value = "/findAll", produces = "application/json;charset=UTF-8") @ResponseBody public String findAll(Model model){ out.println("tmmlReqA表现层:查询到。。。"); List<TmmlReqA> all =tmmlReqAService.findAll(); String str= JSON.toJSON(all).toString(); model.addAttribute("result",str); return str; } }
Controller 获取数据列表,向前台返回json 格式数据
最新推荐文章于 2024-03-12 21:35:38 发布