SSM +Maven 实现 三级联动 无刷新

java代码:

package com.cn.liuweiying.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.json.JsonArray;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.cn.liuweiying.bean.One;
import com.cn.liuweiying.bean.Three;
import com.cn.liuweiying.bean.Two;
import com.cn.liuweiying.service.OneService;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("/lian")
public class LianController {
	protected static Logger logger = Logger.getLogger(LianController.class);
	@Resource
	private OneService oneService;

	@RequestMapping(params = "ToOne", method = { RequestMethod.POST, RequestMethod.GET })
	public ModelAndView ToOne(HttpServletRequest request,HttpServletResponse response) throws IOException {
		ModelAndView view = new ModelAndView();
	
		response.setCharacterEncoding("UTF-8");
		JSONArray jsonarray = null;
		// 查询所有的一级
		List onelist = oneService.findOneAll();
		jsonarray = JSONArray.fromObject(onelist);
		PrintWriter out = response.getWriter();
		out.print(jsonarray.toString());
		out.flush();
		out.close();
		view.addObject("onelist", onelist);
		view.setViewName("lian");
		return view;

	}

	// 获得一级父id获取二级
	@RequestMapping(params = "ToTwo", method = { RequestMethod.POST, RequestMethod.GET })
	public ModelAndView ToTwo(HttpServletRequest request,HttpServletResponse response,Integer one) throws IOException {
		ModelAndView view = new ModelAndView();
		//JSONObject jsonObject = new JSONObject();
		response.setCharacterEncoding("UTF-8");
		JSONArray jsonarray = null;
		One one1 = oneService.selectByPrimaryKeyOne(one);
		int oneid = one1.getOneid();
		List twolist = oneService.findTwoByFaterid(oneid);
		jsonarray = JSONArray.fromObject(twolist);
		PrintWriter out = response.getWriter();
		out.print(jsonarray.toString());
		out.flush();
		out.close();
		view.addObject("twolist", twolist);
		view.setViewName("lian");
		return view;

	}

	// 获得二级父id获得三级
	@RequestMapping(params = "ToThree",  method = { RequestMethod.POST, RequestMethod.GET })
	public ModelAndView ToThree(HttpServletRequest request,HttpServletResponse response,Integer two) throws IOException {
		ModelAndView view = new ModelAndView();
		response.setCharacterEncoding("UTF-8");
		JSONArray jsonarray = null;
		Two two1 = oneService.selectByPrimaryKeybyTwo(two);
		int twoid = two1.getTwoid();
		List threelist = oneService.findThreeByFaterid(twoid);
		jsonarray = JSONArray.fromObject(threelist);
		PrintWriter out = response.getWriter();
		out.print(jsonarray.toString());
		out.flush();
		out.close();
		view.addObject("threelist", threelist);
		view.setViewName("lian");
		return view;
	}

}


jsp代码:
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>






   



Insert title here


	

${message }




效果展示截图:
SSM +Maven 实现 三级联动 无刷新_第1张图片


你可能感兴趣的:(maven)