请阅读此文章前,阅读基础版。
基础版:https://blog.csdn.net/LISHUAICSDN/article/details/93902373
补充版:https://blog.csdn.net/LISHUAICSDN/article/details/94211271
素材包:
链接:https://pan.baidu.com/s/1gzVvVKRQ_n1I3N5e7rtpiw
提取码:0t7o
项目下载地址:
链接:https://pan.baidu.com/s/14QE2KfTULez7qKgRQMzQ3A
提取码:wdoe
右击目名:
如果右下角出现此问题,左键点击即可。
方法如上建立ssm_dao,ssm_service 俩个model。
建立ssm_web的model。与上面的不一样。
此处如果有问题,请看基础版的详细解释。
目录结构如下图所示:
下图的文件是由素材包直接导入的。如有问题请看基础版的详细导入过程。
pom.xml的配置,基础版有详细讲解。pom.xml的配置信息在素材包里有。
4.0.0
firstone
first
pom
1.0-SNAPSHOT
ssm_bean
ssm_dao
ssm_service
ssm_web
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.zhongruan.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;
}
@Override
public String toString() {
return "UserInfo{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
package com.zhongruan.dao;
import com.zhongruan.bean.UserInfo;
import java.util.List;
public interface IUserDao {
public UserInfo doLogin(UserInfo userInfo);
public List findAll();
public void adduserinfo(UserInfo userInfo);
public void deleteuserinfo(int id);
public void updateuserinfo(UserInfo userInfo);
}
package com.zhongruan.service.impl;
import com.zhongruan.bean.UserInfo;
import com.zhongruan.dao.IUserDao;
import com.zhongruan.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Service
public class UserService implements IUserService {
@Autowired
private IUserDao userDao;
@Override
public List findAll() {
return userDao.findAll();
}
@Override
public boolean login(UserInfo userInfo) {
UserInfo userInfo1 = userDao.doLogin(userInfo);
if (userInfo1 != null) {
return true;
} else {
return false;
}
}
@Override
public void adduserinfo(UserInfo userInfo) {
userDao.adduserinfo(userInfo);
}
@Override
public void deleteuserinfo(int id) {
userDao.deleteuserinfo(id);
//return userDao.deleteuserinfo(id);
}
@Override
public void updateuserinfo(UserInfo userInfo) {
userDao.updateuserinfo(userInfo);
}
}
package com.zhongruan.service;
import com.zhongruan.bean.UserInfo;
import java.util.List;
public interface IUserService {
public boolean login(UserInfo userInfo);
//List queryAllUserInfo();
public List findAll();
public void adduserinfo(UserInfo userInfo);
public void deleteuserinfo(int id);
public void updateuserinfo(UserInfo userInfo);
}
import com.zhongruan.bean.UserInfo;
import com.zhongruan.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 java.util.List;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("/Login.do")
public ModelAndView login(UserInfo userInfo)
{
ModelAndView mv =new ModelAndView();
boolean falg= userService.login(userInfo);
if (falg)
{
mv.setViewName("main");
}else {
mv.setViewName("../failer");
}
return mv;
}
@RequestMapping("/findAll.do")
public ModelAndView findAll() {
List all = userService.findAll();
ModelAndView mv = new ModelAndView();
mv.addObject("userinfos", all);
mv.setViewName("user-list");
return mv;
}
@RequestMapping("/deleteuserinfo.do")
public String deleteuserinfo (int id)
{
userService.deleteuserinfo(id);
return "redirect:findAll.do";
}
@RequestMapping("/toAddUser.do")
public String adduserinfo(UserInfo userInfo) {
userService.adduserinfo(userInfo);
return "redirect:findAll.do";
}
@RequestMapping("/update.do")
public String updateuserinfo(UserInfo userInfo) {
userService.updateuserinfo(userInfo);
return "redirect:findAll.do";
}
}
insert into userinfo(id,username,password) VALUE (#{id},#{username},#{password})
delete from userinfo where id=#{id}
update userinfo
set username = #{username},password = #{password}
where id = #{id}
## 3.7 jsp页面的简单修改 login.jsp: ![在这里插入图片描述](https://img-blog.csdnimg.cn/2019070119573059.png) user-list ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190701195816199.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xJU0hVQUlDU0RO,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190701195918521.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xJU0hVQUlDU0RO,size_16,color_FFFFFF,t_70) user-add.jsp ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190701195957120.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0xJU0hVQUlDU0RO,size_16,color_FFFFFF,t_70)