Demo entry 6685574

java

   

Submitted by vaemc on Dec 20, 2017 at 10:03
Language: Java. Code size: 2.0 kB.

package com.goods.Controller;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.goods.Dao.DBHelper;
import com.goods.bean.goodList;



@Controller
public class HomeController {
	private ResultSet ret = null;
	private DBHelper dbh = null;
	
	@RequestMapping("/")
	public ModelAndView login()
	{
		
		return new ModelAndView("login.jsp");
	}
	
	@RequestMapping("/manage")
	public ModelAndView manage()
	{
		ModelAndView mav=new ModelAndView("manage.jsp");
		mav.addObject("gl", gQuery());
		return mav;
	}
	
	@RequestMapping(value="/gUpdate", method = {RequestMethod.POST})  
	@ResponseBody  
	public String gUpdate(HttpServletRequest request,HttpServletResponse response)
	{
		
		int i=0;
		dbh=new DBHelper(request.getParameter("sql"));
		try {
			i=dbh.pst.executeUpdate();
			
		} catch (SQLException e) {
			
			e.printStackTrace();
		} 
		dbh.close();
		
		return String.valueOf(i);
	}
	public ArrayList<goodList> gQuery()
	{
		ArrayList<goodList> gl=new ArrayList<goodList>();
		try {  
		
			dbh=new DBHelper("select *from eshop");
			ret=dbh.pst.executeQuery(); //执行语句
			while (ret.next()) {  
				gl.add(new goodList(ret.getString(1),ret.getString(2),ret.getString(3),ret.getString(4),ret.getString(5),ret.getString(6),ret.getString(7),ret.getString(8),ret.getString(9)));
				
	        }

	        ret.close();  
	        dbh.close();//关闭连接  

			} catch (SQLException e) {  
	            e.printStackTrace();  
	            
	        }  
		
		return gl;
	}
	

}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).