package com.userplay;
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 java.io.IOException;
import java.util.ArrayList;
import java.util.List ;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql. * ;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class UsersController {
@RequestMapping({"/Login","/"})
public String list(Model model) {
return "Login";
}
@RequestMapping(value="/login",method=RequestMethod.POST)
@ResponseBody
public boolean login(String userName,String Password) throws IOException{
boolean result = false;
try
{
Class.forName( "org.postgresql.Driver" ).newInstance();
String url = "jdbc:postgresql://localhost:5432/test" ;
Connection con = DriverManager.getConnection(url, "postgres" , "123456" );
Statement st = con.createStatement();
String sql = "select * from person where name ='"+userName+"' and password = '"+Password+"' ";
ResultSet rs = st.executeQuery(sql);
if (rs.next())
{
result = true;
}
rs.close();
st.close();
con.close();
}
catch (Exception ee)
{
System.out.print(ee.getMessage());
}
return result;
}
@RequestMapping(value="/Show",method=RequestMethod.POST)
@ResponseBody
public List<List<String>> Show() throws IOException{
List<List<String>> listStr = new ArrayList<List<String>>();
try
{
Class.forName( "org.postgresql.Driver" ).newInstance();
String url = "jdbc:postgresql://localhost:5432/test" ;
Connection con = DriverManager.getConnection(url, "postgres" , "123456" );
Statement st = con.createStatement();
String sql = "select * from person order by id";
ResultSet rs = st.executeQuery(sql);
while(rs.next()) {
String id = rs.getInt(1)+"";
String name = rs.getString(2);
String password = rs.getString(3);
List<String> list = new ArrayList<String>();
list.add(id);
list.add(name);
list.add(password);
listStr.add(list);
}
rs.close();
st.close();
con.close();
}
catch (Exception ee)
{
System.out.print(ee.getMessage());
}
return listStr;
}
@RequestMapping(value="/Update")
@ResponseBody
public boolean Update(String userId,String userName,String Password) throws IOException{
int id = Integer.valueOf(userId).intValue();
boolean result = false;
try
{
Class.forName( "org.postgresql.Driver" ).newInstance();
String url = "jdbc:postgresql://localhost:5432/test" ;
Connection con = DriverManager.getConnection(url, "postgres" , "123456" );
Statement st = con.createStatement();
String sql = "update person set name = '"+userName+"',password = '"+Password+"' where id = '"+id+"'";
int count = st.executeUpdate(sql);
if(count > 0){
result = true;
}
st.close();
con.close();
}
catch (Exception ee)
{
System.out.print(ee.getMessage());
}
return result;
}
@RequestMapping(value="/Delete")
@ResponseBody
public boolean Delete(String userId,String userName,String Password) throws IOException{
int id = Integer.valueOf(userId).intValue();
boolean result = false;
try
{
Class.forName( "org.postgresql.Driver" ).newInstance();
String url = "jdbc:postgresql://localhost:5432/test" ;
Connection con = DriverManager.getConnection(url, "postgres" , "123456" );
Statement st = con.createStatement();
String sql = "delete from person where id = '"+id+"' and name = '"+userName+"'and password = '"+Password+"'";
int count = st.executeUpdate(sql);
if(count > 0){
result = true;
}
st.close();
con.close();
}
catch (Exception ee)
{
System.out.print(ee.getMessage());
}
return result;
}
@RequestMapping(value="/Insert")
@ResponseBody
public boolean Insert(HttpServletRequest request,HttpServletResponse response) throws IOException{
String userId = request.getParameter("userId");
int id = Integer.valueOf(userId).intValue();
String userName = request.getParameter("userName");
String userPw = request.getParameter("Password");
boolean result = false;
try
{
Class.forName( "org.postgresql.Driver" ).newInstance();
String url = "jdbc:postgresql://localhost:5432/test" ;
Connection con = DriverManager.getConnection(url, "postgres" , "123456" );
Statement st = con.createStatement();
String sql = "insert into person(id,name,password) values('"+id+"','"+userName+"','"+userPw+"')";
int count = st.executeUpdate(sql);
if(count > 0){
result = true;
}
st.close();
con.close();
}
catch (Exception ee)
{
System.out.print(ee.getMessage());
}
return result;
}
}
Spring mvc+Ajax用户登录增删改查功能
4星 · 超过85%的资源 需积分: 50 63 浏览量
2015-09-24
16:08:50
上传
评论 3
收藏 6.24MB ZIP 举报
丨ice123丨
- 粉丝: 0
- 资源: 4
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页