ssm框架—电影管理系统
① 项目要求:
一、语言和环境
A、实现语言
Java
B、环境要求
idea, JDK, Tomcat , mysql
二、功能要求
某电影院计划使用ssm开发一套订票系统,mysql作为后台数据库。其中“电影管理”功能由你来完成。
要求实现:
1.“电影信息显示页面”功能显示所有电影信息,选择类型,点击查询,可以按类型进行查找该类型的电影信息。
三、数据库设计
数据库名称及要求:数据库名称film_自己名字拼音缩写_日期。例如: film_zhangsan_0918
四、具体要求及推荐实现步骤
1、建立数据库和数据表,并且添加测试数据(至少3条)。
2、打开idea,创建Web工程,命名为film_自己名字缩写_日期,并创建相应包(包名必须包含自己名字缩写)。
3、在工程中创建实体类。
4、创建数据访问接口、业务类,创建对应的实现。
5、创建controller,实现“添加电影信息”和“电影信息显示”功能。
7、实现“显示电影信息”功能,必须检索;
8、实现“添加电影信息”功能,并进行数据校验。
9、测试程序,调试运行成功后,监考老师现场改分。
五、注意事项
1.请注意界面美观,添加适当CSS样式表;
2.请注意代码的书写、命名符合规范,在代码中添加必要的注释;
3.请注意操作数据库时进行必要的异常处理。
② 项目实现:
数据库/表:
注意:要先生成type_info表,再生成film_info表
主页面:
表单页面:
新增(校验):
表单中每一个输入框都有非空校验(如下图),效果展示(和上图相似)。略!
查询:
③ 项目结构整体布局:
④代码:
数据库/表:
数据库:
#创建数据库
create database film_wangwenbiao_0913
#设置字符集
default character set utf8mb4
#设置编码方式
default collate utf8mb4_general_ci
数据表:
create table film_info
(
film_id int primary key auto_increment,
film_name varchar(50) not null,
film_type int not null,
foreign key (film_type)
references type_info(type_id),
film_duration int not null,
release_date date not null,
film_remark varchar(200) not null
);
select * from film_info;
insert into film_info
(film_id,film_name,film_type,film_duration,release_date,film_remark)
values
(1001,'老师好',1,111,'2019-03-22','1985年的南宿一中,苗宛秋(于谦饰)老师推自行车昂首走在校园,接受着人们艳羡的目光和纷至沓来的恭维。三班是一个永远也不缺故事的集体。苗宛秋怎么也不会想到,他即将走进的这个三班将会成为他以及他身边这辆自行车的噩梦。三班的同学也没有想到,这位新来的老师改变了他们的一生。');
create table type_info
(
type_id int primary key auto_increment,
type_name varchar(50) not null
);
select * from film_info;
select * from type_info;
insert into type_info
(type_id,type_name)
values
(1,'戏剧'),
(2,'奇幻'),
(3,'谍战'),
(4,'自然');
配置文件:
pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>film_wwb_0913</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>film_wwb_0913 Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<servlet.version>4.0.1</servlet.version>
<jsp.version>2.2</jsp.version>
<jstl.version>1.2</jstl.version>
<spring.version>5.3.14</spring.version>
<commons-dbcp.version>1.4</commons-dbcp.version>
<mybatis.version>3.4.6</mybatis.version>
<mybatis-spring.version>1.3.3</mybatis-spring.version>
<mysql-connector-java.version>8.0.11</mysql-connector-java.version>
<fastjson.version>1.2.78</fastjson.version>
</properties>
<dependencies>
<!-- 添加javaEE支持 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<!-- provided只在编译时支持,发布时不拷贝文件 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp.version}</version>
<!-- provided只在编译时支持,发布时不拷贝文件 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<!-- 引入spring基础模块 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--dbcp连接池 -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons-dbcp.version}</version>
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!-- mybatis spring整合 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
</dependency>
<!-- mybatis插件PageHelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.0</version>
</dependency>
<!--通用mapper插件-->
<dependency>
<groupId>com.github.abel533</groupId>
<artifactId>mapper</artifactId>
<version>3.0.1</version>
</dependency>
<!-- mysql驱动类 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
</dependency>
<!-- fastjson处理json数据 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- lombok 简化实体内容 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>com.github.xuwei-k</groupId>
<artifactId>html2image</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
</project>
db.properties :
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/film_wangwenbiao_0913?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowPublicKeyRetrieval=true
jdbc.username=root
jdbc.password=123456
mybatis_config.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 配置日志工具 -->
<setting name="logImpl" value="STDOUT_LOGGING"/>
<!--配置将下划线字段转为小驼峰-->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
<plugin interceptor="com.github.abel533.mapperhelper.MapperInterceptor">
<!--主键自增回写方法,默认值MYSQL -->
<property name="IDENTITY" value="MYSQL" />
<!--通用Mapper默认接口 -->
<property name="mappers" value="com.github.abel533.mapper.Mapper" />
</plugin>
</plugins>
</configuration>
spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--扫描包-->
<context:component-scan base-package="com.que.controller"/>
<!--开启注解驱动-->
<mvc:annotation-driven>
<!--配置时间转换器,将后台传到前台的日期数据格式化-->
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/>
</bean>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!--视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/page/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
spring-mybatis.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!--扫包-->
<context:component-scan base-package="com.que.service"/>
<!--配置数据库连接-->
<context:property-placeholder location="classpath:db.properties"/>
<!--配置数据库连接池-->
<bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--配置MySQL的SQLsession对象-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--配置数据源-->
<property name="dataSource" ref="ds"/>
<!--配置类型别名-->
<property name="typeAliasesPackage" value="com.que.entity"/>
<!--配置mybatis主配置文件的路径,其内可以定义特定的配置-->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!--配置mapper文件路径-->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<!--配置mapper接口-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.que.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
</beans>
web.xml :
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!--监听项目启动加载mybatis容器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mybatis.xml</param-value>
</context-param>
<!--字符过滤器-->
<filter>
<filter-name>charactorEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>charactorEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
entity类:
Film_info :
package com.que.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "film_info")
public class Film_info {
@Id
@GeneratedValue(generator = "JDBC",strategy = GenerationType.IDENTITY)
private Integer filmId;
private String filmName;
private Integer filmType;
private Integer filmDuration;
private Date releaseDate;
private String filmRemark;
}
Type_info :
package com.que.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "type_info")
public class Type_info {
@Id
@GeneratedValue(generator = "JDBC",strategy = GenerationType.IDENTITY)
private Integer typeId;
private String typeName;
}
CommonResult :
package com.que.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/*
*@Auther jjk
*@Date 2022/8/29*
*@Description
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult {
//编码:0成功,1失败
private Integer code;
//提示消息
private String msg;
//记录数
private Integer count;
//记录数据
private Object data;
//返回查询结果的成功信息:
public static CommonResult success(Integer count, Object data){
return new CommonResult(0,"success",count,data);
}
//返回增删改的成功信息
public static CommonResult success(){
return new CommonResult(0,"success",null,null);
}
//返回失败信息
public static CommonResult fail(){
return new CommonResult(1,"fail",null,null);
}
}
mapper接口:
FilmMapper :
package com.que.mapper;
import com.github.abel533.mapper.Mapper;
import com.que.entity.Film_info;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface FilmMapper extends Mapper<Film_info> {
List<Map> listAll(@Param("filmType") Integer filmType);
}
TypeMapper :
package com.que.mapper;
import com.github.abel533.mapper.Mapper;
import com.que.entity.Type_info;
import java.util.List;
public interface TypeMapper extends Mapper<Type_info> {
List<Type_info> listAll();
}
mapper接口实现:
FilmMapper.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.que.mapper.FilmMapper">
<select id="listAll" resultType="map">
select f.film_id,f.film_name,f.film_type,f.film_duration,f.release_date,f.film_remark,
t.type_id,t.type_name
from film_info f
join type_info t
on f.film_type=t.type_id
<where>
<if test="filmType!=null and filmType!='' ">
and film_type=#{filmType}
</if>
</where>
</select>
</mapper>
TypeMapper.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.que.mapper.TypeMapper">
<select id="listAll" resultType="Type_info">
select * from type_info
</select>
</mapper>
业务接口/类:
IFilmService :
package com.que.service;
import com.que.entity.Film_info;
import java.util.List;
import java.util.Map;
public interface IFilmService {
List<Map> listAll(Integer filmType);
int insertFilm(Film_info film_info);
}
ITypeService :
package com.que.service;
import com.que.entity.Type_info;
import java.util.List;
public interface ITypeService {
List<Type_info> listAll();
}
FilmServiceImpl :
package com.que.service.impl;
import com.que.entity.Film_info;
import com.que.mapper.FilmMapper;
import com.que.service.IFilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class FilmServiceImpl implements IFilmService {
@Autowired
private FilmMapper filmMapper;
@Override
public int insertFilm(Film_info film_info) {
return filmMapper.insertSelective(film_info);
}
@Override
public List<Map> listAll(Integer filmType) {
return filmMapper.listAll(filmType);
}
}
TypeServiceImpl :
package com.que.service.impl;
import com.que.entity.Type_info;
import com.que.mapper.FilmMapper;
import com.que.mapper.TypeMapper;
import com.que.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TypeServiceImpl implements ITypeService {
@Autowired
private TypeMapper typeMapper;
@Override
public List<Type_info> listAll() {
return typeMapper.listAll();
}
}
controller:
FilmController :
package com.que.controller;
import com.alibaba.fastjson.JSONObject;
import com.que.entity.CommonResult;
import com.que.entity.Film_info;
import com.que.service.IFilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/film")
public class FilmController {
@Autowired
private IFilmService iFilmService;
@RequestMapping("listAll")
public CommonResult listAll(Integer filmType){
System.out.println("============listAll============");
System.out.println("返回结果:"+iFilmService.listAll(filmType));
List<Map> filmMap=iFilmService.listAll(filmType);
if(filmMap.size()!=0){
return CommonResult.success(filmMap.size(),filmMap);
}else{
return CommonResult.fail();
}
}
@RequestMapping("insert")
public int insert(@RequestParam("film") String jsonStr ){
System.out.println("============insert============");
System.out.println("返回结果:"+jsonStr);
JSONObject jsonObject=JSONObject.parseObject(jsonStr);
Film_info film_info=new Film_info();
film_info.setFilmName((String) jsonObject.get("film_name"));
film_info.setFilmType(Integer.valueOf((String) jsonObject.get("film_type")) );
film_info.setFilmDuration(Integer.valueOf((String) jsonObject.get("film_duration")));
film_info.setReleaseDate(jsonObject.getDate("release_date"));
film_info.setFilmRemark((String) jsonObject.get("film_remark"));
return iFilmService.insertFilm(film_info);
}
}
TypeController :
package com.que.controller;
import com.que.entity.Type_info;
import com.que.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("type")
public class TypeController {
@Autowired
private ITypeService iTypeService;
@RequestMapping("listAll")
public List<Type_info> listAll(){
return iTypeService.listAll();
}
}
ForwardController :
package com.que.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/forward")
public class ForwardController {
@RequestMapping("/toFilm")
public String toFilm(){
return "film";
}
}
jsp:
film.jsp :
<%--
Created by IntelliJ IDEA.
User: 33154
Date: 2022/9/13
Time: 19:59
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">
</head>
<body>
<!--定义表格工具条-->
<script type="text/html" id="filmBar">
<div class="layui-btn-container">
<!--lay-event:用于设置一个按钮的特定事件,事件名字自己定义-->
<button type="button" class="layui-btn" lay-event="filmAdd">新增</button>
</div>
</script>
<form class="layui-form" action="" style="margin-top: 20px">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">类型:</label>
<div class="layui-input-block">
<select name="film_type" id="film_type0" lay-verify="required" >
<option value="">请选择</option>
</select>
</div>
</div>
<div class="layui-inline">
<div class="layui-input-block">
<button type="button" class="layui-btn" lay-submit lay-filter="filmQuery">查询</button>
</div>
</div>
</div>
</form>
<!--要渲染的数据表格-->
<table id="film" lay-filter="film"></table>
<script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
<%--display: none;--%>
<!--弹出表单-->
<form class="layui-form" action="" style="display: none;margin:10px" id="filmFrm" lay-filter="filmFrm">
<!--设置提交的地址-->
<input type="hidden" id="action" name="action">
<div class="layui-form-item">
<label class="layui-form-label">编号</label>
<div class="layui-input-block">
<input type="button" name="film_id" value="自动生成" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">电影名称</label>
<div class="layui-input-block">
<input type="text" name="film_name" lay-verify="film_name" lay-verify="required" placeholder="请输入电影名称" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">类型</label>
<div class="layui-input-block">
<select name="film_type" id="film_type" lay-verify="required" >
<option value="">请选择</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">时长</label>
<div class="layui-input-block">
<input type="text" name="film_duration" lay-verify="required" placeholder="请输入电影时长" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">上映时间</label>
<div class="layui-input-block">
<input type="text" name="release_date" id="release_date" lay-verify="required" placeholder="年/月/日" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">简介</label>
<div class="layui-input-block">
<textarea name="film_remark" placeholder="请输入内容" lay-verify="required" class="layui-textarea"></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="button" class="layui-btn" lay-submit lay-filter="filmBtnSubmit">立即提交</button>
<button type="button" class="layui-btn layui-btn-primary" id="filmBtnConcle" >取消</button>
</div>
</div>
</form>
<script>
layui.use(['table','layer','laydate','form'], function(){
var table = layui.table //表格组件
,layer=layui.layer //弹出层
,laydate=layui.laydate //日期
,form=layui.form //表单
,$ = layui.$; //jq
laydate.render({
elem:'#release_date'
});
//加载部门下拉框
loadFilmInfo();
//查询
form.on('submit(filmQuery)', function(data){
//console.log(data);
console.log(data.field.film_type);
table.reload('film',{
where:{
filmType:data.field.film_type
}
})
});
//校验电影名字
form.verify({
film_name : function(value, item){ //value:表单的值、item:表单的DOM对象
if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
return '电影名称不能有特殊字符';
}
if(/(^\_)|(\__)|(\_+$)/.test(value)){
return '电影名称首尾不能出现下划线\'_\'';
}
if(/^\d+\d+\d$/.test(value)){
return '电影名称不能全为数字';
}
//如果不想自动弹出默认提示框,可以直接返回 true,这时你可以通过其他任意方式提示(v2.5.7 新增)
if(value === 'xxx'){
alert('电影名称不能为敏感词');
return true;
}
}
});
//渲染表格数据
table.render({
elem: '#film'
,url: '${pageContext.request.contextPath}/film/listAll'
,toolbar:"#filmBar" //设置表格工具条
,cols: [[ //表格列的定义
//film_id,film_name,film_type,film_duration,release_date,film_remark
{field:'film_id', title: '电影编号'}
,{field:'film_name' , title: '电影名称' }
,{field:'film_type', title: '电影类型',templet:function (d){
//console.log(d);
if(d.film_type==1)
return "戏剧";
else if(d.film_type==2)
return "奇幻";
else if(d.film_type==3)
return "谍战";
else if(d.film_type==4)
return "自然";
}}
,{field:'film_duration' , title: '时长'}
,{field:'release_date', title: '上映时间'}
,{field:'film_remark',title: '备注'}
]]
});
function loadFilmInfo(){
$.ajax({
url:"${pageContext.request.contextPath}/type/listAll",
type:"get",
success:function(res){
console.log(res);
for (var i=0;i<res.length;i++){
var film=res[i];
$("#film_type0").append("<option value='"+film.typeId+"'>"+film.typeName+"</option>")
$("#film_type").append("<option value='"+film.typeId+"'>"+film.typeName+"</option>")
}
//重新渲染下拉框
form.render('select')
}
})
}
table.on('toolbar(film)', function(obj){
console.log(obj);
// var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
case 'filmAdd':
// layer.msg('添加');
clearFilmFrm();
$('#action').val("${pageContext.request.contextPath}/film/insert");
showFilmFrm();
break;
};
});
form.on('submit(filmBtnSubmit)', function(obj){
console.log(obj);
$.ajax({
url:$('#action').val(),
type:"post",
data:{"film":JSON.stringify(obj.field)},
dateType:"json",
success:function (res){
console.log("从contorller返回的int:"+res);
if(res==1){
layer.msg("操作成功",{icon:6});
//关闭表单
layer.close(showFilmFrmIndex);
//表单重置
//$("#userFrm")[0].reset();
clearFilmFrm();
//刷新表格
table.reload('film');
}else{
layer.msg("添加失败",{icon:5});
}
}
})
});
$('#filmBtnConcle').on('click',function (){
layer.close(showFilmFrmIndex);
})
//弹出表单
var showFilmFrmIndex;
function showFilmFrm(){
showFilmFrmIndex=layer.open({
type:1,
area:['600px','600px'],
title:"新增电影",
content:$('#filmFrm')
})
};
//表单重置
function clearFilmFrm(){
$("#filmFrm")[0].reset();
}
/*form.on('submit(filmBtnConcle)', function() {
layer.close(showFilmFrmIndex);
})*/
});
</script>
</body>
</html>
index.jsp :
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>Hello World!</h2>
<a href="${pageContext.request.contextPath}/forward/toFilm">页面</a>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/118030.html