多表联查,多条件查询,ajax返回值乱码,前台循环展示json数据

多表联查,多条件查询

@Data
public class hangyunxingxi {

    private int hangyunid;

    private int rid;

    private int starid;

    private int endid;

    private int dateid;

    private String hangcheng;

    private float price;

    private String rname;

    private String starname;

    private String endname;

    private String date;

}

        


    

    


前台页面展示,解决ajax返回值乱码

使用ajax请求返回前台的时候会出现乱码的情况,需要在@RequestMapping中添加produces = "application/json; charset=utf-8"

 //查询并展示所有航运信息
    @RequestMapping(value = "hangyunlist",method = RequestMethod.POST , produces = "application/json; charset=utf-8")
    @ResponseBody
    public String hangyunxingxilist(HttpServletResponse response){
        response.setContentType("text/html;charset=utf-8");
        List hangyunxingxis = zlxService.queryHangyunxingxi();

        Gson gson2=new Gson();
        String str=gson2.toJson(hangyunxingxis);

        return str;
    }

    //更具条件查询航运信息
    @RequestMapping("reach")
    public String reachhangyun(String rname,String starname,String endname,String date){  // hy 参数表示从前台传回的所有查询条件

        List hangyunxingxis = zlxService.reachHangyunxingxi(rname,starname,endname,date);

        System.out.println("查询信息" + hangyunxingxis);

        return "";
    }
<%--    航运信息表格--%>
    

你可能感兴趣的:(多表联查,多条件查询,ajax返回值乱码,前台循环展示json数据)