stationcondition.java

来自「用spring做的一个拥有添加」· Java 代码 · 共 74 行

JAVA
74
字号
package com.mvc.Beans;

import java.util.*;
import javax.servlet.http.*;

import org.springframework.jdbc.core.*;
import org.springframework.web.servlet.*;
import org.springframework.web.servlet.mvc.*;

public class stationCondition implements Controller{
	public JdbcTemplate jtl;
	
	public JdbcTemplate getJtl() {
		return jtl;
	}

	public void setJtl(JdbcTemplate jtl) {
		this.jtl = jtl;
	}

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("GBK");
		String sname=request.getParameter("sname");
		String division=request.getParameter("division");
		String company=request.getParameter("company");
		
		String ctl="  ";
		int label=0;
		
		if(!sname.equals(" ")){
			ctl = " sname like '%"+sname+"%' ";
			label=1;
		}
		
		if(!division.equals(" ") && label==1){
			ctl =ctl + " and division like '%"+division+"%' ";
		}
		if(!division.equals(" ") && label==0){
			ctl = " division like '%"+division+"%' ";
			label=1;
		}
		
		if(!company.equals(" ") && label == 1){
			ctl =ctl + " and company like '%"+company+"%' ";
		}
		if(!company.equals(" ") && label==0){
			ctl = " company like '%"+company+"%' ";
			label=1;
		}
		
		if(label==0){
			List list=jtl.queryForList("select * from station");
			return new ModelAndView("ListStation","list",list);
		}
		else{
			List list=jtl.queryForList("select * from station where "+ctl+" ");
			if(list.isEmpty()){
				Map msg = new HashMap();
				msg.put("msg", "没有这一条记录!");
				
				return  new ModelAndView("ConditionStation",msg);
			}
			return new ModelAndView("ListStation","list",list);
		}
		
	}

	
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?