工具:
IDEA 2018 2.2
mySQL5.5+SQLyog
alimaven
central
aliyun maven
http://maven.aliyun.com/nexus/content/repositories/central/
UTF-8
1.7
1.7
5.0.2.RELEASE
3.2.6
1.7.7
1.2.17
0.9.5.2
1.1.2
org.springframework
spring-core
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-oxm
${spring.version}
org.springframework
spring-tx
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-aop
${spring.version}
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-test
${spring.version}
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
1.2.2
javax
javaee-api
7.0
mysql
mysql-connector-java
5.1.30
commons-dbcp
commons-dbcp
1.2.2
jstl
jstl
1.2
log4j
log4j
${log4j.version}
com.mchange
c3p0
${c3p0.version}
taglibs
standard
${taglibs.version}
org.slf4j
slf4j-api
${slf4j.version}
org.slf4j
slf4j-log4j12
${slf4j.version}
javax.servlet
javax.servlet-api
3.1.0
provided
javax.servlet.jsp
javax.servlet.jsp-api
2.3.1
provided
package com.bean;
public class UserInfo {
private int id; //三个对应数据库的变量
private String username;
private String password;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.dao;
import com.bean.UserInfo;
import java.util.List;
public interface IUserDao { //接口 在UserMapper中实现接口
public List findall();
public void deleteUser(int id);
public void updateUser(UserInfo userInfo);
public void addUser(UserInfo userInfo);
UserInfo queryId(int id);
UserInfo checkUser(String username);
}
package com.service;
import com.bean.UserInfo;
import javax.xml.registry.infomodel.User;
import java.util.List;
public interface IUserservice {
public List findall();
public void deleteUser(int id);
public void addUser(UserInfo userInfo);
public void updateUser(UserInfo userInfo);
UserInfo queryId(int id);
UserInfo checkUser(String username);
}
package com.service.impl;
import com.bean.UserInfo;
import com.dao.IUserDao;
import com.service.IUserservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserService implements IUserservice {
@Autowired
private IUserDao userDao;
@Override
public List findall() {
return userDao.findall();
}
@Override
public void deleteUser(int id) {
userDao.deleteUser(id);
}
@Override
public void addUser(UserInfo userInfo) {
userDao.addUser(userInfo);
}
@Override
public void updateUser(UserInfo userInfo) {
userDao.updateUser(userInfo);
}
@Override
public UserInfo queryId(int id) {
return userDao.queryId(id);
}
@Override
public UserInfo checkUser(String username) {
return userDao.checkUser(username);
}
}
package com.dao;
import com.bean.UserInfo;
import java.util.List;
public interface IUserDao { //接口 在UserMapper中实现接口
public List findall();
public void deleteUser(int id);
public void updateUser(UserInfo userInfo);
public void addUser(UserInfo userInfo);
UserInfo queryId(int id);
UserInfo checkUser(String username);
}
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/idea?useSSL=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=1234
# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
insert into userinfo(id,username,password) value (#{id},#{username},#{password})
delete from userinfo where id=#{id}
update userinfo set id=#{id},username=#{username},password=#{password} where id=#{id}
package com.controller;
import com.bean.UserInfo;
import com.service.IUserservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserservice userService;
@RequestMapping("/findAll.do")
public ModelAndView findall(){
List all=userService.findall();
ModelAndView mv=new ModelAndView();
mv.addObject("userinfos",all);
mv.setViewName("allUser");
return mv;
}
@RequestMapping("/todeleteUser.do")
public String deleteUser(int id){
userService.deleteUser(id);
return "redirect:findAll.do";
}
@RequestMapping("/toAddUser.do")
public String toAddUser(){
return "addUser";
}
@RequestMapping("/save.do")
public String AddUser(UserInfo userInfo){
userService.addUser(userInfo);
return "redirect:findAll.do";
}
@RequestMapping("/toUpdateUser.do")
public String toupdateUser(UserInfo userInfo,int id){
userInfo=userService.queryId(id);
return "updateUser";
}
@RequestMapping("/update.do")
public String updateUser(UserInfo userInfo){
userService.updateUser(userInfo);
userInfo=userService.queryId(userInfo.getId());
return "redirect:findAll.do";
}
@RequestMapping("/inUser.do")
public String login(HttpServletRequest request){
String username= request.getParameter("username");
String password=request.getParameter("password");
boolean flag=logincheck(username,password);
if(flag){
return "redirect:findAll.do";
}
else{
return "inUser";
}
}
private boolean logincheck(String username,String password){
UserInfo userInfo=userService.checkUser(username);
if(userInfo==null||"".equals(username)){
return false;
}
if(userInfo.getPassword().equals(password)){
return true;
}
else{
return false;
}
}
}
public List findall();
public List findall();
@Autowired
private IUserDao userDao;
@Override
public List findall() {
return userDao.findall();
}
@Autowired
private IUserservice userService;
@RequestMapping("/findAll.do")
public ModelAndView findall(){
List all=userService.findall();
ModelAndView mv=new ModelAndView();
mv.addObject("userinfos",all);
mv.setViewName("allUser");
return mv;
}
-这些是JSP文件
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
user列表
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
新增用户
基于SSM框架的管理系统:简单实现增、删、改、查。
新增用户
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
修改论文
基于SSM框架的管理系统:简单实现增、删、改、查。
修改用户
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
Hello World!
查询所有文件
登录界面
到此整个数据库的增删查改就实现完了
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
用户登录
UserInfo checkUser(String username);
UserInfo checkUser(String username);
@Override
public UserInfo checkUser(String username) {
return userDao.checkUser(username);
}
@RequestMapping("/inUser.do")
public String login(HttpServletRequest request){
String username= request.getParameter("username");
String password=request.getParameter("password");
boolean flag=logincheck(username,password);
if(flag){
return "redirect:findAll.do";
}
else{
return "inUser";
}
}
private boolean logincheck(String username,String password){
UserInfo userInfo=userService.checkUser(username);
if(userInfo==null||"".equals(username)){
return false;
}
if(userInfo.getPassword().equals(password)){
return true;
}
else{
return false;
}
}
这样整个登录界面就实现完了