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配置(略)
/*
Navicat Premium Data Transfer
Source Server : test
Source Server Type : MySQL
Source Server Version : 50640
Source Host : localhost:3306
Source Schema : community_db
Target Server Type : MySQL
Target Server Version : 50640
File Encoding : 65001
Date: 31/05/2022 16:49:17
*/
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;
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
insert into tb_community values(0,"${name}",#{existing},#{completed})
delete from tb_community where id=#{id}
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/community_db?characterEncoding=utf-8
username=root
password=12345678
index.jsp
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext.xml
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
forceEncoding
true
CharacterEncodingFilter
/*
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
1
true
springmvc
/
创建【com.item】下的【controller】【dao】【model】【service】【serviceimpl】五层
创建【webapp】下【views】视图层
package com.item.model;
public class TbCommunity {
private int id;
private String name;
private int existing;
private int completed;
@Override
public String toString() {
return "TbCommunity{" +
"id=" + id +
", name='" + name + '\'' +
", existing=" + existing +
", completed=" + completed +
'}';
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getExisting() {
return existing;
}
public void setExisting(int existing) {
this.existing = existing;
}
public int getCompleted() {
return completed;
}
public void setCompleted(int completed) {
this.completed = completed;
}
}
package com.item.dao;
import java.util.*;
import com.item.model.TbCommunity;
import org.apache.ibatis.annotations.Param;
public interface TbCommunityMapper {
List GetInfo();
List SelectByName(@Param("name") String name);
int AddInfo(
@Param("name") String name,
@Param("existing") int existing,
@Param("completed") int completed
);
int DeleteById(@Param("id") int id);
}
package com.item.service;
import com.item.model.TbCommunity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface TbCommunityService {
/**
* 查询所有
* @return
*/
List GetInfo();
List SelectByName(String name);
int AddInfo(
String name,
int existing,
int completed
);
int DeleteById(int id);
}
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);
}
}
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";
}
/**
* 添加
* @return
*/
@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";
}
}
<%@ 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()%>
删除
<%
}
%>
添加 共计<%=list.size()%>条数据
<%--
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" %>
添加
添加信息
祝大家考试顺利。
访问路径:端口号根据自己的配置些啊:
【http://localhost:8088/GetInfo】