Java_SSM_tb_community对照编码(全部源码)-Java文档类资源-CSDN下载
最终效果:(包含需要的所有样式都写了)
添加页面
删除提示:
目录
1、数据库环境MySQL脚本
2、创建项目
3、基础配置文件位置
pom.xml
mapper.xml
jdbc.properties
applicationContext.xml
spring-mvc.xml
web.xml
4、各层级包创建
5、完成各层编码
【com.item.model/TbCommunity.java】
【com.item.dao/TbCommunityMapper.java】
【com.item.service/TbCommunityService.java】
【com.item.serviceimpl/TbCommunityServiceImpl.java】
【com.item.controller/TbCommunityController.java】
【webapp/views/GetInfo.jsp】
【webapp/views/AddInfoPage.jsp】
tomcat配置(略)
1、数据库环境MySQL脚本
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for tb_community
-- ----------------------------
DROp TABLE IF EXISTS `tb_community`;
CREATE TABLE `tb_community` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`existing` int(11) NOT NULL,
`completed` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of tb_community
-- ----------------------------
INSERT INTO `tb_community` VALUES (1, '平壤们社区', 12000, 32345);
INSERT INTO `tb_community` VALUES (2, '红光社区', 22000, 42121);
INSERT INTO `tb_community` VALUES (3, '鱼梁洲社区', 42000, 21215);
INSERT INTO `tb_community` VALUES (4, '桥口社区', 32125, 13212);
INSERT INTO `tb_community` VALUES (5, '汉阳社区', 7000, 129832);
SET FOREIGN_KEY_CHECKS = 1;
2、创建项目
整个替换【dependencies】内所有内容
3、基础配置文件位置
pom.xml
junit
junit
4.11
test
mysql
mysql-connector-java
5.1.47
org.mybatis
mybatis
3.5.9
javax.servlet
javax.servlet-api
3.1.0
javax.servlet.jsp
javax.servlet.jsp-api
2.3.3
org.springframework
spring-core
4.3.18.RELEASE
org.springframework
spring-web
4.3.18.RELEASE
org.springframework
spring-context
4.3.18.RELEASE
org.springframework
spring-beans
4.3.18.RELEASE
org.springframework
spring-webmvc
4.3.18.RELEASE
org.springframework
spring-jdbc
4.3.18.RELEASE
org.springframework
spring-tx
4.3.18.RELEASE
org.mybatis
mybatis-spring
2.0.6
javax.servlet
jstl
1.2
commons-dbcp
commons-dbcp
1.4
commons-fileupload
commons-fileupload
1.3.1
commons-io
commons-io
2.4
com.alibaba
fastjson
2.0.4
com.alibaba
druid
1.1.10
com.alibaba
druid-spring-boot-starter
1.2.9
mapper.xml
jdbc.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/community_db?characterEncoding=utf-8
username=root
password=12345678
applicationContext.xml
【com.item.serviceimpl/TbCommunityServiceImpl.java】
package com.item.serviceimpl;
import com.item.dao.TbCommunityMapper;
import com.item.model.TbCommunity;
import com.item.service.TbCommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TbCommunityServiceImpl implements TbCommunityService {
@Autowired
private TbCommunityMapper tbCommunityMapper;
@Override
public List GetInfo() {
return tbCommunityMapper.GetInfo();
}
@Override
public List SelectByName(String name) {
return tbCommunityMapper.SelectByName(name);
}
@Override
public int AddInfo(String name, int existing, int completed) {
return tbCommunityMapper.AddInfo(name,existing,completed);
}
@Override
public int DeleteById(int id) {
return tbCommunityMapper.DeleteById(id);
}
}
【com.item.controller/TbCommunityController.java】
package com.item.controller;
import com.item.model.TbCommunity;
import com.item.service.TbCommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
public class TbCommunityController {
@Autowired
private TbCommunityService db;
@GetMapping("/GetInfo")
public String GetInfo(HttpServletRequest request, Model model){
List list = db.GetInfo();
model.addAttribute("lists",list);
return "GetInfo";
}
@GetMapping("/SelectByName")
public String SelectByName(HttpServletRequest request, Model model){
String name = request.getParameter("name");
List list = db.SelectByName(name);
model.addAttribute("lists",list);
return "GetInfo";
}
@GetMapping("/AddInfoPage")
public String AddInfoPage(){
return "AddInfoPage";
}
@PostMapping("/AddInfo")
public String AddInfo(HttpServletRequest request){
String name = request.getParameter("name");
String existing = request.getParameter("existing");
String completed = request.getParameter("completed");
db.AddInfo(name, Integer.parseInt(existing), Integer.parseInt(completed));
return "redirect:/GetInfo";
}
@GetMapping("/DeleteById")
public String DeleteById(HttpServletRequest request){
String id = request.getParameter("id");
db.DeleteById(Integer.parseInt(id));
return "redirect:/GetInfo";
}
}
【webapp/views/GetInfo.jsp】
<%@ page import="java.util.*" %>
<%@ page import="com.item.model.TbCommunity" %><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/5/31 0031
Time: 10:37
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
显示
<% List list = (List) request.getAttribute("lists");%>
编号
用户名
接种疫苗
已接种疫苗
操作
<%
for (TbCommunity t : list) {
%>
<%=t.getId()%>
<%=t.getName()%>
<%=t.getExisting()%>
<%=t.getCompleted()%>
" onclick="return confirm('是否删除此行?')">删除
<%
}
%>
添加 共计<%=list.size()%>条数据
【webapp/views/AddInfoPage.jsp】
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/5/31 0031
Time: 10:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
添加
添加信息
jdbc.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/community_db?characterEncoding=utf-8
username=root
password=12345678
applicationContext.xml
【com.item.serviceimpl/TbCommunityServiceImpl.java】
package com.item.serviceimpl;
import com.item.dao.TbCommunityMapper;
import com.item.model.TbCommunity;
import com.item.service.TbCommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TbCommunityServiceImpl implements TbCommunityService {
@Autowired
private TbCommunityMapper tbCommunityMapper;
@Override
public List GetInfo() {
return tbCommunityMapper.GetInfo();
}
@Override
public List SelectByName(String name) {
return tbCommunityMapper.SelectByName(name);
}
@Override
public int AddInfo(String name, int existing, int completed) {
return tbCommunityMapper.AddInfo(name,existing,completed);
}
@Override
public int DeleteById(int id) {
return tbCommunityMapper.DeleteById(id);
}
}
【com.item.controller/TbCommunityController.java】
package com.item.controller;
import com.item.model.TbCommunity;
import com.item.service.TbCommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
public class TbCommunityController {
@Autowired
private TbCommunityService db;
@GetMapping("/GetInfo")
public String GetInfo(HttpServletRequest request, Model model){
List list = db.GetInfo();
model.addAttribute("lists",list);
return "GetInfo";
}
@GetMapping("/SelectByName")
public String SelectByName(HttpServletRequest request, Model model){
String name = request.getParameter("name");
List list = db.SelectByName(name);
model.addAttribute("lists",list);
return "GetInfo";
}
@GetMapping("/AddInfoPage")
public String AddInfoPage(){
return "AddInfoPage";
}
@PostMapping("/AddInfo")
public String AddInfo(HttpServletRequest request){
String name = request.getParameter("name");
String existing = request.getParameter("existing");
String completed = request.getParameter("completed");
db.AddInfo(name, Integer.parseInt(existing), Integer.parseInt(completed));
return "redirect:/GetInfo";
}
@GetMapping("/DeleteById")
public String DeleteById(HttpServletRequest request){
String id = request.getParameter("id");
db.DeleteById(Integer.parseInt(id));
return "redirect:/GetInfo";
}
}
【webapp/views/GetInfo.jsp】
<%@ page import="java.util.*" %>
<%@ page import="com.item.model.TbCommunity" %><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/5/31 0031
Time: 10:37
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
显示
<% List list = (List) request.getAttribute("lists");%>
编号
用户名
接种疫苗
已接种疫苗
操作
<%
for (TbCommunity t : list) {
%>
<%=t.getId()%>
<%=t.getName()%>
<%=t.getExisting()%>
<%=t.getCompleted()%>
" onclick="return confirm('是否删除此行?')">删除
<%
}
%>
添加 共计<%=list.size()%>条数据
【webapp/views/AddInfoPage.jsp】
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/5/31 0031
Time: 10:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
添加
添加信息
【com.item.serviceimpl/TbCommunityServiceImpl.java】 package com.item.serviceimpl; import com.item.dao.TbCommunityMapper; import com.item.model.TbCommunity; import com.item.service.TbCommunityService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class TbCommunityServiceImpl implements TbCommunityService { @Autowired private TbCommunityMapper tbCommunityMapper; @Override public ListGetInfo() { return tbCommunityMapper.GetInfo(); } @Override public List SelectByName(String name) { return tbCommunityMapper.SelectByName(name); } @Override public int AddInfo(String name, int existing, int completed) { return tbCommunityMapper.AddInfo(name,existing,completed); } @Override public int DeleteById(int id) { return tbCommunityMapper.DeleteById(id); } } 【com.item.controller/TbCommunityController.java】
<% Listpackage com.item.controller; import com.item.model.TbCommunity; import com.item.service.TbCommunityService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import javax.servlet.http.HttpServletRequest; import java.util.List; @Controller public class TbCommunityController { @Autowired private TbCommunityService db; @GetMapping("/GetInfo") public String GetInfo(HttpServletRequest request, Model model){ Listlist = db.GetInfo(); model.addAttribute("lists",list); return "GetInfo"; } @GetMapping("/SelectByName") public String SelectByName(HttpServletRequest request, Model model){ String name = request.getParameter("name"); List list = db.SelectByName(name); model.addAttribute("lists",list); return "GetInfo"; } @GetMapping("/AddInfoPage") public String AddInfoPage(){ return "AddInfoPage"; } @PostMapping("/AddInfo") public String AddInfo(HttpServletRequest request){ String name = request.getParameter("name"); String existing = request.getParameter("existing"); String completed = request.getParameter("completed"); db.AddInfo(name, Integer.parseInt(existing), Integer.parseInt(completed)); return "redirect:/GetInfo"; } @GetMapping("/DeleteById") public String DeleteById(HttpServletRequest request){ String id = request.getParameter("id"); db.DeleteById(Integer.parseInt(id)); return "redirect:/GetInfo"; } } 【webapp/views/GetInfo.jsp】
<%@ page import="java.util.*" %> <%@ page import="com.item.model.TbCommunity" %><%-- Created by IntelliJ IDEA. User: Administrator Date: 2022/5/31 0031 Time: 10:37 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %>显示 list = (List ) request.getAttribute("lists");%>
<% for (TbCommunity t : list) { %> 编号 用户名 接种疫苗 已接种疫苗 操作 <% } %> <%=t.getId()%> <%=t.getName()%> <%=t.getExisting()%> <%=t.getCompleted()%> " onclick="return confirm('是否删除此行?')">删除 添加 共计<%=list.size()%>条数据
【webapp/views/AddInfoPage.jsp】
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/5/31 0031
Time: 10:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
添加
添加信息
添加信息
tomcat配置(略)
祝大家考试顺利。
访问路径:端口号根据自己的配置些啊:
【http://localhost:8088/GetInfo】