前端:html+css+jvavscript vue框架 + ajax + axios + element ui
后端:jvav + mybatis框架 + mysql数据库
项目管理工具:maven
服务器:Tomcat
相关功能演示
首先启动Tomcat服务器
进入页面
调整每页显示数量:
页面跳转:
添加数据:
删除数据:
条件查询:
条件查询下的页面切换:
前端源码:
Title
查询
删除
添加
立即创建
取消
修改
删除
后端源码(部分):
Dao层
mapper(实现对数据库的操作)
package com.company.web.mapper;
import com.company.web.pojo.Brand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface BrandMapper {
@Select("select * from brand")
List select();
@Insert("insert into brand values(null,#{name },#{company},#{ordered},#{description},#{status})")
void add(Brand brand);
//@Delete("delete from brand where ??????")
void del(@Param("ids") int[] ids);
@Select("select * from brand limit #{begin},#{size}")
List selectByPage(@Param("begin") int begin, @Param("size") int size);
@Select("select count(*) from brand")
int selectCount();
//List selectx(@Param("status")int status,@Param("name") String name,@Param("company") String company,@Param("begin")int begin, @Param("size")int size);
List selectx(@Param("brand")Brand brand, @Param("begin") int begin, @Param("size") int size);
//@Select("select count(*) from brand where ???")
int selectCountx(Brand brand);
}
mapper的xml配置
delete from brand where id in #{id}
service层(封装操作数据库的方法)
package com.company.web.server;
import com.company.web.pojo.Brand;
import com.company.web.mapper.BrandMapper;
import com.company.web.pojo.PageBean;
import com.company.web.servlet.SSF;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import java.util.List;
public class BrandServer {
public List select() {
//1.加载mybatis核心配置文件
SqlSessionFactory sqlSessionFactory = SSF.factory();
//2.获取SqlSession对象,用它执行sql
SqlSession sqlSession = sqlSessionFactory.openSession();
//3.执行sql
BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class);
List list = brandMapper.select();
sqlSession.close();
return list;
}
public PageBean selectx(Brand brand, int currentPage, int pageSize) {
//1.加载mybatis核心配置文件
SqlSessionFactory sqlSessionFactory = SSF.factory();
//2.获取SqlSession对象,用它执行sql
SqlSession sqlSession = sqlSessionFactory.openSession();
//3.执行sql
BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class);
String name = brand.getName();
if (name != null && name.length() > 0) {
brand.setName("%" + name + "%");
}
String company = brand.getCompany();
if (company != null && company.length() > 0) {
brand.setCompany("%" + company + "%");
}
if (brand.getStatus() == 0) {
brand.setStatus(null);
}
int begin = (currentPage - 1) * pageSize;
int size = pageSize;
List list = brandMapper.selectx(brand, begin, size);
int countx = brandMapper.selectCountx(brand);
PageBean pageBean = new PageBean(list, countx);
sqlSession.close();
return pageBean;
}
public PageBean selectByPage(int currentPage, int pageSize) {
//1.加载mybatis核心配置文件
SqlSessionFactory sqlSessionFactory = SSF.factory();
//2.获取SqlSession对象,用它执行sql
SqlSession sqlSession = sqlSessionFactory.openSession();
//3.执行sql
BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class);
int begin = (currentPage - 1) * pageSize;
int size = pageSize;
int count = brandMapper.selectCount();
List list = brandMapper.selectByPage(begin, size);
PageBean pageBean = new PageBean(list, count);
sqlSession.close();
return pageBean;
}
public void add(Brand brand) {
//1.加载mybatis核心配置文件
SqlSessionFactory sqlSessionFactory = SSF.factory();
//2.获取SqlSession对象,用它执行sql
SqlSession sqlSession = sqlSessionFactory.openSession();
//3.执行sql
BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class);
brandMapper.add(brand);
sqlSession.commit();
sqlSession.close();
}
public void del(int[] ids) {
//1.加载mybatis核心配置文件
SqlSessionFactory sqlSessionFactory = SSF.factory();
//2.获取SqlSession对象,用它执行sql
SqlSession sqlSession = sqlSessionFactory.openSession();
//3.执行sql
BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class);
brandMapper.del(ids);
sqlSession.commit();
sqlSession.close();
}
}
servlet层(响应请求,调用service的方法)
package com.company.web.servlet;
import com.alibaba.fastjson.JSON;
import com.company.web.pojo.Brand;
import com.company.web.pojo.PageBean;
import com.company.web.server.BrandServer;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
@WebServlet(urlPatterns = {"/selectxServlet"})
public class SelectxServlet extends HttpServlet {
BrandServer brandServer = new BrandServer();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String _CurrentPage = req.getParameter("currentPage");
String _PageSize= req.getParameter("pageSize");
int currentPage = Integer.parseInt(_CurrentPage);
int pageSize = Integer.parseInt(_PageSize);
BufferedReader reader = req.getReader();
String json = reader.readLine();
Brand brand = JSON.parseObject(json,Brand.class);
PageBean pageBean = brandServer.selectx(brand,currentPage,pageSize);
json = JSON.toJSONString(pageBean);
resp.setContentType("text/json;charset=utf8");
resp.getWriter().write(json);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
doGet(req, resp);
}
}
至此,已完成对jvav se 、jvav sql、jvav web的学习,下面将开启spring篇
完整源码过于啰嗦,这里就不放了,有需要者欢迎评论/私信获取
世界线回溯,从jvav到架构师



