基于java的旅游管理系统_项目管理系统源码JAVA

(7) 2024-09-19 07:01:01

产品管理页面

  • 页面介绍
  • 后台代码
    • 依赖安装(pom.xml)
    • 项目资源配置(resource)
      • applicationContext.xml
      • db.properties
      • log4j.properties
      • springmvc.xml
      • spy.properties
    • SSM架构(Model、Controller、View)
      • 数据库封装类(entity)
      • 数据库操作类(Dao)
      • Service层接口实现类(ServiceImpl)
      • Service层接口(Service)
      • 控制器层(Controller)
    • 数据库(Mysql)

页面介绍

旅游管理系统基于JavaSSM框架,Maven,Mysql数据库,Bootstrap动态页面,springMVC,mybatis等,其中产品管理页面有增删改查,动态显示,分页显示,多行删除的功能。

后台代码

依赖安装(pom.xml)

基于java的旅游管理系统_项目管理系统源码JAVA (https://mushiming.com/)  第1张pom.xml作为Maven架构中用于管理:源代码、配置文件、开发者的信息和角色、问题追踪系统、组织信息、项目授权、项目的url、项目的依赖关系的文件。十分重要,首先要在pom文件中把项目所要用到的相关依赖插件安装。

项目资源配置(resource)

基于java的旅游管理系统_项目管理系统源码JAVA (https://mushiming.com/)  第2张

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 开启注解扫描,管理service和dao --> <context:component-scan base-package="com.yzw.service"> </context:component-scan> <context:component-scan base-package="com.yzw.dao"> </context:component-scan> <context:property-placeholder location="classpath:db.properties" /> <!-- 配置数据库数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <!-- 创建spring工厂 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <!-- 传入PageHelper的插件 --> <property name="plugins"> <array> <!-- 传入插件的对象 --> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <props> <prop key="helperDialect">mysql</prop> <prop key="reasonable">true</prop> </props> </property> </bean> </array> </property> </bean> <!-- 扫描dao/mapper接口文件 --> <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.yzw.dao" /> <!-- 如果还有有些专门针对于mybatis的配置,需要引入 --> </bean> </beans> 

该文件用于配置数据源和过滤扫描器

db.properties

jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/pms?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC&rewriteBatchedStatements=true jdbc.username=root jdbc.password= ## P6SpyDriver jdbc.driver=com.p6spy.engine.spy.P6SpyDriver jdbc.url=jdbc:p6spy:mysql://localhost:3306/pms?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC&rewriteBatchedStatements=true jdbc.username=root jdbc.password= 

该文件用于连接mysql数据库

log4j.properties

### 设置### log4j.rootLogger = debug,stdout,D,E ### 输出信息到控制台 ### log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{ 
   yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n ### 输出DEBUG 级别以上的日志到=D://logs/error.log ### log4j.appender.D = org.apache.log4j.DailyRollingFileAppender log4j.appender.D.File = D://logs/log.log log4j.appender.D.Append = true log4j.appender.D.Threshold = DEBUG log4j.appender.D.layout = org.apache.log4j.PatternLayout log4j.appender.D.layout.ConversionPattern = %-d{ 
   yyyy-MM-dd HH:mm:ss} [ %t:%r ]-[ %p ] %m%n ### 输出ERROR 级别以上的日志到=D://logs/error.log ### log4j.appender.E = org.apache.log4j.DailyRollingFileAppender log4j.appender.E.File =D://logs/error.log log4j.appender.E.Append = true log4j.appender.E.Threshold = ERROR log4j.appender.E.layout = org.apache.log4j.PatternLayout 

该文件用于输出错误及DEBUG日志

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 配置包扫描 --> <context:component-scan base-package="com.yzw.controller"> </context:component-scan> <!-- 添加springmvc注解驱动 --> <mvc:annotation-driven /> <!-- 配置视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- JSP文件所在的目录 --> <property name="prefix" value="/pages/" /> <!-- 文件的后缀名 --> <property name="suffix" value=".jsp" /> </bean> <!--配置静态资源不过滤--> <mvc:default-servlet-handler/> <!-- 支持AOP的注解支持,AOP底层使用代理技术 JDK动态代理,要求必须有接口 cglib代理,生成子类对象,proxy-target-class="true" 默认使用cglib的方式 --> <aop:aspectj-autoproxy proxy-target-class="true"/> </beans> 

该文件用于配置视图解析器,从而找到页面进行显示

spy.properties

driverlist=com.mysql.jdbc.Driver autoflush = true appender=com.p6spy.engine.spy.appender.StdoutLogger 

该文件用于监视SQL语句操作

SSM架构(Model、Controller、View)

基于java的旅游管理系统_项目管理系统源码JAVA (https://mushiming.com/)  第3张

数据库封装类(entity)

package com.yzw.entity; public class Product { 
    private Integer id; private String productNum; private String productName; private String cityName; private String departureTime; private Double productPrice; private String productDesc; private Integer productStatus; // 1.无参和有参的构造方法 // 2.set/get // 3.tostring方法 //有参构造方法 public Product(Integer id, String productNum, String productName, String cityName, String departureTime, Double productPrice, String productDesc, Integer productStatus) { 
    super(); this.id = id; this.productNum = productNum; this.productName = productName; this.cityName = cityName; this.departureTime = departureTime; this.productPrice = productPrice; this.productDesc = productDesc; this.productStatus = productStatus; } //无参构造方法 public Product() { 
    super(); } //产品ID public Integer getId() { 
    return id; } public void setId(Integer id) { 
    this.id = id; } //产品编号 public String getProductNum() { 
    return productNum; } public void setProductNum(String productNum) { 
    this.productNum = productNum; } //产品名称 public String getProductName() { 
    return productName; } public void setProductName(String productName) { 
    this.productName = productName; } //城市名称 public String getCityName() { 
    return cityName; } public void setCityName(String cityName) { 
    this.cityName = cityName; } //出发时间 public String getDepartureTime() { 
    return departureTime; } public void setDepartureTime(String departureTime) { 
    this.departureTime = departureTime; } //产品价格 public Double getProductPrice() { 
    return productPrice; } public void setProductPrice(Double productPrice) { 
    this.productPrice = productPrice; } //产品描述 public String getProductDesc() { 
    return productDesc; } public void setProductDesc(String productDesc) { 
    this.productDesc = productDesc; } //产品状态 public Integer getProductStatus() { 
    return productStatus; } public void setProductStatus(Integer productStatus) { 
    this.productStatus = productStatus; } //tostring方法 @Override public String toString() { 
    return "Product [id=" + id + ", productNum=" + productNum + ", productName=" + productName + ", cityName=" + cityName + ", departureTime=" + departureTime + ", productPrice=" + productPrice + ", productDesc=" + productDesc + ", productStatus=" + productStatus + "]"; } } 

将数据库中的数据进行封装,同时构建有参和无参的构造方法。
创建每个字段的get/set方法以此来进行数据的引用和添加。
构建toString()方法将封装类输出转换为String类型

在Eclipse中,通过在Prodect类中右键–>Source可以实现快速构建有参/无参、get/set、toString方法,步骤如下:
基于java的旅游管理系统_项目管理系统源码JAVA (https://mushiming.com/)  第4张
基于java的旅游管理系统_项目管理系统源码JAVA (https://mushiming.com/)  第5张
1.构建有参/无参:
基于java的旅游管理系统_项目管理系统源码JAVA (https://mushiming.com/)  第6张

有参为全选(selectAll),无参为全不选(deselectAll)

2.Get/Set方法
基于java的旅游管理系统_项目管理系统源码JAVA (https://mushiming.com/)  第7张
3.toString方法
基于java的旅游管理系统_项目管理系统源码JAVA (https://mushiming.com/)  第8张

数据库操作类(Dao)

package com.yzw.dao; import java.util.List; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; import com.yzw.entity.Product; public interface ProductDao { 
    // 查询语句 @Select("select * from product") public List<Product> selectAll(); // 添加语句 @Insert("insert product values(#{id},#{productNum},#{productName},#{cityName},#{departureTime},#{productPrice},#{productDesc},#{productStatus})") public int insertProduct(Product product); // 删除语句 @Delete("delete from product where id=#{id}") public int deleteProduct(int id); // 修改语句 @Update("update product set productNum=#{productNum},productName=#{productName},cityName=#{cityName},departureTime=#{departureTime},productPrice=#{productPrice},productDesc=#{productDesc},productStatus=#{productStatus} where id=#{id}") public int updateProduct(Product product); // 根据id查询语句(通过id向修改页面传值) @Select("select * from product where id = #{id}") public Product selectProductById(Integer id); // 单行删除语句 @Delete("delete from product where id=#{id}") public int deleteProductOne(Integer id); } 

Service层接口实现类(ServiceImpl)

package com.yzw.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.yzw.dao.ProductDao; import com.yzw.entity.Product; import com.yzw.service.ProductService; @Service public class ProductServiceImpl implements ProductService { 
    // 声明变量 @Autowired // 变量注解:不为空 private ProductDao productDao; // 实体类返回DAO层的查询数据 @Override public List<Product> selectAll() { 
    // TODO Auto-generated method stub return productDao.selectAll(); } @Override public int insertProduct(Product product) { 
    // TODO Auto-generated method stub return productDao.insertProduct(product); } @Override public boolean deleteProduct(Integer[] ids) { 
    // TODO Auto-generated method stub for (int i = 0; i < ids.length; i++) { 
    productDao.deleteProduct(ids[i]); } return true; } @Override public int updateProduct(Product product) { 
    // TODO Auto-generated method stub return productDao.updateProduct(product); } @Override public Product selectProductById(Integer id) { 
    // TODO Auto-generated method stub return productDao.selectProductById(id); } @Override public int deleteProductOne(Integer id) { 
    // TODO Auto-generated method stub return productDao.deleteProductOne(id); } } 

Service层接口(Service)

package com.yzw.service; import java.util.List; import com.yzw.entity.Product; public interface ProductService { 
    // 返回实体类的查询结果 List<Product> selectAll(); int insertProduct(Product product); boolean deleteProduct(Integer[] ids); int updateProduct(Product product); Product selectProductById(Integer id); int deleteProductOne(Integer id); } 

控制器层(Controller)

package com.yzw.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.yzw.entity.Product; import com.yzw.service.ProductService; @Controller @RequestMapping("/product") public class ProductController { 
    // 声明变量 @Autowired // 变量注解:不为空 private ProductService productService; // 只返回数据的方法 @RequestMapping("selectAllData") @ResponseBody public PageInfo<Product> selectAllData( @RequestParam(name = "pageNum", defaultValue = "1", required = false) Integer pageNum, @RequestParam(name = "pageSize", defaultValue = "20", required = false) Integer pageSize) { 
    // 1.开启分页 PageHelper.startPage(pageNum, pageSize); // 2.执行查询语句 List<Product> list = productService.selectAll(); // 3.封装pageinfo类 PageInfo<Product> pageInfo = new PageInfo<Product>(list); return pageInfo; } // 只返回页面的方法 @RequestMapping("selectAllView") public ModelAndView selectAllView() { 
    ModelAndView mav = new ModelAndView(); mav.setViewName("product-list"); return mav; } /* 2.添加产品 */ @RequestMapping("/insertProduct") @ResponseBody public ModelAndView insertProduct(Product product) { 
    ModelAndView mav = new ModelAndView(); int flag = productService.insertProduct(product); if (flag == 0) { 
   // 添加失败返回本页面 mav.setViewName("product-add"); } else { 
   // 返回产品列表页面,并查询数据 // 执行查询全部产品 mav = selectAllView(); } return mav; } /* 3.批量删除产品 */ @RequestMapping("/deleteProducts") @ResponseBody public boolean deleteProduct(Integer[] ids) { 
    return productService.deleteProduct(ids); } /* 4.单行删除产品 */ @RequestMapping("/deleteProductOne") @ResponseBody public int deleteProductOne(Integer id) { 
    return productService.deleteProductOne(id); } /* 5.修改产品 */ @RequestMapping("/updateProduct") @ResponseBody public ModelAndView updateProduct(Integer id) { 
    // 1.获取要修改的信息 Product product = productService.selectProductById(id); // 2.跳转到修改页面 ModelAndView mav = new ModelAndView(); mav.setViewName("product-update"); mav.addObject("product", product); return mav; } // 6.修改产品,返回页面 @RequestMapping("/updateProductData") public ModelAndView updateProductData(Product product) { 
    // 1.获取要修改的信息 int flag = productService.updateProduct(product); // 2.跳转到对应页面 ModelAndView mav = new ModelAndView(); if (flag > 0) { 
   // 修改成功,跳转到产品列表页面 mav.setViewName("product-list"); } else { 
   // 修改失败,继续回到修改页面 mav.setViewName("product-update"); } return mav; } } 

数据库(Mysql)

-- 创库 drop database if exists pms; create database pms character set utf8; use pms; #产品表 product drop table if exists product; create table product( id int(11) not null primary key auto_increment comment '主键', productNum varchar(60) not null unique comment '产品编号', productName varchar(60) comment '产品名称', cityName varchar(20) comment '出发城市', departureTime datetime comment '出发时间', productPrice double(10,2) comment '产品价格', productDesc varchar(500) comment '产品描述', productStatus int(1) comment '产品状态(0 关闭 1 开启)' ); -- 创建存储过程pro_insertMany,循环插入数据  drop PROCEDURE if exists pro_insertMany; DELIMITER // CREATE PROCEDURE pro_insertMany(IN nums INT) BEGIN DECLARE i INT DEFAULT 1; WHILE i<=nums DO insert into product values(null,i,'江西武功山3日游','武汉','2020-10-24 10:00:00',1888.00,'来咯表哥',1); SET i=i+1; END WHILE; END// DELIMITER ; -- 调用存储过程pro_insertMany,插入120条随机数据 CALL pro_insertMany(120); select * from product; 
THE END

发表回复