TFYWBaseMapper.xml
后台链接数据库oracle,注意关联表字段名相同查询必须起别名(二级联动所有数据全部查询到前端再进行联动判断)
用file标签上传文件,value值只能从后端处理,file里只存文件框点击里面的值,并且只存点击最后一个文件值
列表List根据类别,标题相似,开始结束创建时间来筛选功能
<?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="TFYWBaseMapper">
<!-- 基础映射 -->
<resultMap type="com.fh.entity.tfyw.TFYWBase" id="tfywBaseMap">
<id property="base_id" column="BASE_ID"/>
<result property="title" column="TITLE"/>
<result property="gjz" column="GJZ"/>
<result property="createtime" column="CREATETIME" jdbcType="VARCHAR"/>
<result property="show_lev" column="SHOW_LEV"/>
<result property="worktime" column="WORKTIME"/>
<result property="sfcy" column="SFCY" jdbcType="VARCHAR" javaType="String"/>
<result property="log" column="LOG" jdbcType="VARCHAR" javaType="String"/>
<result property="blck" column="BLCK"/>
<result property="sfzpyc" column="SFZPYC"/>
<result property="sfxcbl" column="SFXCBL"/>
<result property="sfwsbl" column="SFWSBL"/>
<association property="typeSub" javaType="com.fh.entity.tf.TypeSub">
<id property="t_id" column="type_two"/>
<result property="type_name" column="type_name"/>
<result property="mark" column="mark"/>
<association property="type" javaType="com.fh.entity.tf.Type">
<id property="typeId" column="o_id1"/>
<result property="image" column="image"/>
<result property="typeName" column="type_name1"/>
<result property="mark" column="mark1"/>
</association>
</association>
</resultMap>
<!-- 包含所有字段的SQL片段 -->
<sql id="showAll">
s.base_id,s.title,s.type_two,s.createtime,s.show_lev,s.worktime,s.gjz,s.sfcy,s.log,s.blck,s.sfzpyc,s.sfxcbl,s.sfwsbl
</sql>
<!-- 业务信息 列表展示 带分页和模糊查询 -->
<select id="selectAlllistPage" resultMap="tfywBaseMap" parameterType="page">
select <include refid="showAll"/>,t.t_id,t.o_id,t.type_name,t.mark,o.o_id as o_id1,o.type_name as type_name1,o.mark as mark1
from t_tfwx_base s left join t_tfwx_type_two t
on s.type_two = t.t_id left join t_tfwx_type_one o
on t.o_id = o.o_id
<where>
<if test="1 == 1">
1=1
</if>
<if test="pd.text != null and pd.text != ''">
AND s.title LIKE '%' || #{pd.text} || '%'
</if>
<if test="pd.begin != null and pd.begin != ''">
AND s.createtime > to_date(#{pd.begin},'yyyy-mm-dd')
</if>
<if test="pd.end != null and pd.end != ''">
AND s.createtime < to_date(#{pd.end},'yyyy-mm-dd')
</if>
<if test="pd.selectState != null and pd.selectState != '' and pd.selectState != -1">
AND s.type_two = #{pd.selectState}
</if>
<if test="1 == 1">
AND s.type_two != '-1'
</if>
</where>
ORDER BY s.createtime
</select>
<!-- 选择所有查询类型 -->
<select id="selectAllType" resultType="pd">
select o_id as o_id1,type_name as type_name1,mark as mark1 from t_tfwx_type_one
</select>
<!-- 查询所有子类型 -->
<select id="selectChildType" resultType="pd">
select t_id,o_id,type_name,mark from t_tfwx_type_two
</select>
<!-- 查询单个信息-->
<select id="selectOneById" resultMap="tfywBaseMap" parameterType="pd">
select <include refid="showAll"/>,t.t_id,t.o_id,t.type_name,t.mark,o.o_id as o_id1,o.type_name as type_name1,o.mark as mark1
from t_tfwx_base s left join t_tfwx_type_two t
on s.type_two = t.t_id left join t_tfwx_type_one o
on t.o_id = o.o_id where s.base_id = #{id,jdbcType=VARCHAR}
</select>
<!-- 插入查询内容 -->
<insert id="insertOne">
insert into t_tfwx_base (
base_id,
title,
type_two,
createtime,
show_lev,
worktime,
gjz,
sfcy,
log,
blck,
sfzpyc,
sfxcbl,
sfwsbl
)
values(
#{base_id,jdbcType=VARCHAR},
#{title,jdbcType=VARCHAR},
#{typeSub.t_id,jdbcType=VARCHAR},
to_date(#{createtime,jdbcType=VARCHAR},'yyyy-mm-dd hh24:mi:ss'),
#{show_lev,jdbcType=INTEGER},
#{worktime,jdbcType=VARCHAR},
#{gjz,jdbcType=VARCHAR},
#{sfcy,jdbcType=VARCHAR},
#{log,jdbcType=CLOB},
#{blck,jdbcType=VARCHAR},
#{sfzpyc,jdbcType=VARCHAR},
#{sfxcbl,jdbcType=VARCHAR},
#{sfwsbl,jdbcType=VARCHAR}
)
</insert>
<!-- 通过id删除-->
<delete id="deleteById" parameterType="pd">
delete from t_tfwx_base
where base_id = #{id,jdbcType=VARCHAR}
</delete>
<!-- 通过id更新 -->
<update id="update" parameterType="com.fh.entity.tfyw.TFYWBase">
UPDATE t_tfwx_base set
<if test="typeSub.t_id != null and typeSub.t_id != ''">
type_two = #{typeSub.t_id,jdbcType=VARCHAR},
</if>
<if test="show_lev != null and show_lev != ''">
show_lev = #{show_lev,jdbcType=INTEGER},
</if>
<if test="worktime != null and worktime != ''">
worktime = #{worktime,jdbcType=VARCHAR},
</if>
<if test="gjz != null and gjz != ''">
gjz = #{gjz,jdbcType=VARCHAR},
</if>
<if test="sfcy != null and sfcy != ''">
sfcy = #{sfcy,jdbcType=VARCHAR},
</if>
<if test='sfcy=="Y" and log != null and log != "" or sfcy=="N"'>
log = #{log,jdbcType=VARCHAR},
</if>
<!-- <if test="click != null and click != ''">
click = #{click,jdbcType=INTEGER},
</if> -->
<if test="blck != null and blck != ''">
blck = #{blck,jdbcType=VARCHAR},
</if>
<if test="sfzpyc != null and sfzpyc != ''">
sfzpyc = #{sfzpyc,jdbcType=VARCHAR},
</if>
<if test="sfxcbl != null and sfxcbl != ''">
sfxcbl = #{sfxcbl,jdbcType=VARCHAR},
</if>
<if test="sfwsbl != null and sfwsbl != ''">
sfwsbl = #{sfwsbl,jdbcType=VARCHAR},
</if>
title = #{title,jdbcType=VARCHAR}
WHERE base_id = #{base_id,jdbcType=VARCHAR}
</update>
</mapper>
tfywBase_update.jsp(是否常用,是即必须选择Log图片,否则不能保存Log,二级联动用foreach标签浏览判断)
获得单个信息返回值是实体类,EL表达式用实体类属性名,获得类别返回值PageData,EL表达式用数据库对应字段名
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String imagePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/updateFiles/";
%>
<!DOCTYPE html>
<html lang="zh">
<head>
<base href="<%=basePath%>">
<!--引入CSS-->
<link rel="stylesheet" type="text/css"
href="plugins/fileuploader/webuploader.css">
<!--引入JS-->
<script type="text/javascript"
src="plugins/fileuploader/webuploader.noimage.min.js"></script>
<!-- ace styles -->
<link rel="stylesheet" href="assets/css/ace.css"
class="ace-main-stylesheet" id="main-ace-style" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="assets/css/ace-part2.css" class="ace-main-stylesheet" />
<![endif]-->
<!--[if lte IE 9]>
<link rel="stylesheet" href="assets/css/ace-ie.css" />
<![endif]-->
<!-- inline styles related to this page -->
<!-- ace settings handler -->
<script src="assets/js/ace-extra.js"></script>
<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->
<!--[if lte IE 8]>
<script src="components/html5shiv/dist/html5shiv.min.js"></script>
<script src="components/respond/dest/respond.min.js"></script>
<![endif]-->
<!-- jsp文件头和头部 -->
<%@ include file="../system/admin/top.jsp"%>
<style type="text/css">
textarea {
height: 45%;
width: 50%;
}
</style>
</head>
<body>
<form name="myform" id="form" method="post"
enctype="multipart/form-data" action="<%=basePath%>tfywBase/update.do"
onsubmit="return CheckPost();">
<div class="form-group">
<div id="zhongxin" style="padding: 30px 30px 0px;">
<table id="table_report"
class="table table-striped table-bordered table-hover "
style="text-align: center;">
<tbody>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">标题:</td>
<td><input type="text" id="title" name="title" maxlength="12"
value="${tfywBase.title}" /></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">一级类别:</td>
<td><select id="typeIdSelectionNew" name="type_one"
onchange="search_type(this.options[this.options.selectedIndex].value)">
<option selected="selected"
value="${tfywBase.typeSub.type.typeId}">${tfywBase.typeSub.type.typeName}</option>
<c:forEach items="${typeList}" var="type">
<option value="${type.O_ID1}">${type.TYPE_NAME1}</option>
</c:forEach>
</select></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">二级类别:</td>
<td><select id="typeIdSelection" name="type_two">
<option selected="selected" value="${tfywBase.typeSub.t_id}">${tfywBase.typeSub.type_name}</option>
</select></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">热度:</td>
<td><select id="show_lev" name="show_lev">
<option selected="selected" value="${tfywBase.show_lev}">${tfywBase.show_lev}</option>
</select></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">是否只跑一次</td>
<td><select id="sfzpyc" name="sfzpyc">
</select></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">是否现场办理</td>
<td><select id="sfxcbl" name="sfxcbl">
</select></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">是否网上办理</td>
<td><select id="sfwsbl" name="sfwsbl">
</select></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">办理窗口:</td>
<td><input type="text" id="blck" name="blck" value="${tfywBase.blck}"
placeholder="在此输入办理窗口" /></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">办理时间:</td>
<td><input type="text" id="worktime" name="worktime"
value="${tfywBase.worktime}" /></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">关键字:</td>
<td><input type="text" id="gjz" name="gjz"
value="${tfywBase.gjz}" /></td>
</tr>
<tr>
<td style="width:90px;text-align: right;padding-top: 13px;">是否常用</td>
<td><select id="sfcy" name="sfcy">
</select></td>
</tr>
</tbody>
<tr id="showorhide">
<td style="width:90px;text-align: right;padding-top: 13px;">Log图片:
</td>
<td><input id="log" type="file" name="log" title="图片"
class="file-btn" readonly="readonly" placeholder="点击选择图片"
style="width:9;text-align: right;padding-top: 13px;"></td>
</tr>
<tr id="showorhide1">
<td style="width:90px;text-align: right;padding-top: 13px;">
</td>
<td>
<div id="view"
style="position:relative;width: 40%;height: 350px;float: left;margin-right:10%;border: 0.25rem dashed #A5A5C7;text-align: center">
<c:if test="${tfywBase.log!=null}">
<img src="<%=imagePath%>${tfywBase.log}" alt="" id="icon"
width="100%" height="350px" />
</c:if>
</div>
</td>
</tr>
<tr>
<td style="text-align: center;" colspan="10"><a
class="btn btn-mini btn-primary"><input type="submit"
id="save" value="保存"
style="border:none;background:none;cursor:pointer"></a> <a
class="btn btn-mini btn-danger" onclick="cancel();">取消</a></td>
</tr>
</tbody>
</table>
<div id="saveValue">
<input type="hidden" id="base_id" name="base_id"
value="${tfywBase.base_id}" />
</div>
</div>
</div>
<div id="zhongxin2" class="center" style="display:none">
<br /> <br /> <br /> <br /> <img src="static/images/jiazai.gif" /><br />
<h4 class="lighter block green"></h4>
</div>
</form>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>
<script src="static/js/myjs/md5.js"></script>
<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script>
<!-- 下拉框 -->
<script type="text/javascript"
src="static/js/bootstrap-datepicker.min.js"></script>
<!-- 日期框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script>
<!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
<!--提示框-->
<!--[if lte IE 8]>
<link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<script src="assets/js/html5shiv.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
<script type="text/javascript">
$(function () {
top.hangge();
$('#show_lev').empty();
//填充热度option
for (var i = 1; i < 11; i++){
$('#show_lev').append('<option value="'+i+'">'+i+'</option>');
}
//填充是否常用option
var aa = "${tfywBase.sfcy}";
if(aa=='Y'){
$('#sfcy').append('<option value="Y">是</option>');
$('#sfcy').append('<option value="N">否</option>');
}
if(aa=='N'){
$('#sfcy').append('<option value="N">否</option>');
$('#sfcy').append('<option value="Y">是</option>');
}
if(aa=='Y'){
//显示图片框
$('#showorhide').show();
$('#showorhide1').show();
}
if(aa=='N'){
//隐藏图片框
$('#showorhide').hide();
$('#showorhide1').hide();
}
//填充是否只跑一次option
var bb = "${tfywBase.sfzpyc}";
if(bb=='Y'){
$('#sfzpyc').append('<option value="Y">是</option>');
$('#sfzpyc').append('<option value="N">否</option>');
}
if(bb=='N'){
$('#sfzpyc').append('<option value="N">否</option>');
$('#sfzpyc').append('<option value="Y">是</option>');
}
//填充是否现场办理option
var cc = "${tfywBase.sfxcbl}";
if(cc=='Y'){
$('#sfxcbl').append('<option value="Y">是</option>');
$('#sfxcbl').append('<option value="N">否</option>');
}
if(cc=='N'){
$('#sfxcbl').append('<option value="N">否</option>');
$('#sfxcbl').append('<option value="Y">是</option>');
}
//填充是否网上办理option
var dd = "${tfywBase.sfwsbl}";
if(dd=='Y'){
$('#sfwsbl').append('<option value="Y">是</option>');
$('#sfwsbl').append('<option value="N">否</option>');
}
if(dd=='N'){
$('#sfwsbl').append('<option value="N">否</option>');
$('#sfwsbl').append('<option value="Y">是</option>');
}
//加载日期框
$('.date-picker').datepicker();
//加载热度选择
$('#show_lev').find("option[value = '"+ $('#show_levValue').val() +"']").attr("selected","selected");
//加载类型选择
$('#typeIdSelection').find("option[value = '"+ $('#typeid').val() +"']").attr("selected","selected");
});
//如果选择Y则显示图片框
$("#sfcy").change(function () {
var ss = $(this).children('option:selected').val();
if (ss == "Y") {
$('#showorhide').show();
$('#showorhide1').show();
} else if (ss == "N"||ss == "-1") {
$('#showorhide').hide();
$('#showorhide1').hide();
}
});
$("#typeIdSelectionNew").change(function () {
var selectState = $(this).children('option:selected').val();
//alert("selectState");
//alert(selectState);
$('#typeIdSelection').empty();
if (selectState != "-1") {
$('#typeIdSelection').append('<option selected="selected" value="-1">请选择</option>');
<c:forEach items="${typeChildList}" var="typeChild">
if(${typeChild.O_ID}==selectState){
$('#typeIdSelection').append('<option value="${typeChild.T_ID}">${typeChild.TYPE_NAME}</option>');
}
</c:forEach>
}
});
function cancel() {
top.jzts();
$.ajax({
type: 'get',
url: 'tfywBase/list.do',
success: function (result) {
$('#page-content').html(result);
}
});
}
function CheckPost()
{
if (myform.title.value=="")
{
alert("请输入标题");
myform.title.focus();
return false;
}
if (myform.type_one.value == "-1") {
alert("请选择一级类别");
myform.type_one.focus();
return false;
}
if (myform.type_two.value == "-1") {
alert("请选择二级类别");
myform.type_two.focus();
return false;
}
if (myform.show_lev.value == "-1") {
alert("请选择热度");
myform.show_lev.focus();
return false;
}
if (myform.blck.value == "") {
alert("请输入办理窗口");
myform.blck.focus();
return false;
}
if (myform.worktime.value == "") {
alert("请输入办理时间");
myform.worktime.focus();
return false;
}
if (myform.gjz.value == "") {
alert("请输入关键字");
myform.gjz.focus();
return false;
}
if (myform.sfcy.value == "-1") {
alert("请选择是否常用");
myform.sfcy.focus();
return false;
}
if (myform.sfcy.value == "Y" && myform.log.value == ""&& "${tfywBase.log}" == "") {
alert("请选择Log图片");
myform.log.focus();
return false;
}
if (myform.sfcy.value == "Y" && myform.log.value != "") {
var strs = new Array(); //定义一数组
var log = myform.log.value; //获取input框的值,文件路径
strs = log.split('.'); //分成数组存储
var suffix = strs[strs.length - 1]; //获取文件后缀
if (suffix != 'jpg' && suffix != 'gif' && suffix != 'jpeg'&& suffix != 'png' && suffix != 'bmp') {
alert("您选择的不是图片,请上传一个图片");//不是图片,做处理
return false;
}
}
}
//找到文件选择控制
var img = document.getElementById("log");
//绑定文件控件的选择事件
img.onchange = function() {
//获取当前控件上选择的文件列表
var files = this.files;
//找到预览区域
var view = document.getElementById("view");
//清空预览区域
view.innerHTML = "";
//遍历选择的每个文件
//for(var i=0; i<files.length; i++){
//生成每个图片文件的URL
//var file=files[i];
var url = window.URL.createObjectURL(files[0]);
//创建 <img> 元素
var im = new Image();
//将图片的URL赋值 img 元素的src属性,显示图片
im.src = url;
//将图片添加到预览区域
view.appendChild(im);
//}
};
</script>
</body>
</html>
TFYWBaseController.java(添加或修改后用view视图重定向到列表list)
package com.fh.controller.tfyw;
import java.io.File;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
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.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import com.fh.controller.base.BaseController;
import com.fh.entity.Page;
import com.fh.entity.blzl.BaseBLZL;
import com.fh.entity.tf.TypeSub;
import com.fh.entity.tfyw.TFYWBase;
import com.fh.json.JsonResult;
import com.fh.service.blzl.BLZLService;
import com.fh.service.tfyw.TFYWBaseService;
import com.fh.util.Const;
import com.fh.util.DateUtil;
import com.fh.util.PageData;
import com.fh.util.UuidUtil;
/**
*
* @Title:TFYW
* @Description: 主要业务逻辑控制器
* @author linsa
* @version V1.0
* @date 2018年4月10日
*/
@Controller
@RequestMapping("/tfywBase")
public class TFYWBaseController extends BaseController {
private static Logger logger = Logger.getLogger(TFYWBaseController.class);
@Autowired
private TFYWBaseService tfywBaseService;
@Resource
private BLZLService blzlService;
/**
* 业务与文件关系列表
*/
@RequestMapping(value = "/addDetail")
public ModelAndView QAByList() throws Exception {
ModelAndView mv = this.getModelAndView();
PageData pd = new PageData();
pd = this.getPageData();
// 调用service方法,获取业务资料列表
List<BaseBLZL> baseBLZL = blzlService.list(pd);
mv.addObject("baseBLZL", baseBLZL);
mv.addObject("pd",pd);
mv.setViewName("blzl/blzl_list");
return mv;
}
/**
* 页面展示
* @param page
* @return
*/
@RequestMapping("/list")
public ModelAndView list(Page page){
PageData pageData = this.getPageData();
ModelAndView mav = this.getModelAndView();
page.setPd(pageData);
try {
//获得当前页面列表的所有值
List<TFYWBase> tfywBaseList = tfywBaseService.selectAlllistPage(page);
//获得所有类别
List<PageData> typeList = tfywBaseService.selectAllType();
//获得所有子类别
List<PageData> typeChildList = tfywBaseService.selectChildType();
mav.addObject("typeChildList",typeChildList);
mav.addObject("typeList",typeList);
//获得所有子类别
mav.addObject("tfywBaseList",tfywBaseList);
logger.info("tfywBaseList:" + tfywBaseList);
mav.addObject("page",page);
//给页面返回列表页面
mav.setViewName("tfywBase/tfywBase_list");
} catch (Exception e) {
e.printStackTrace();
}
return mav;
}
/**
* 返回添加页面
* @return
*/
@RequestMapping("/add_show")
public ModelAndView showAddPage(){
ModelAndView mav = this.getModelAndView();
try {
//获得所有类别
List<PageData> typeList = tfywBaseService.selectAllType();
mav.addObject("typeList",typeList);
//给页面返回增加页面
mav.setViewName("tfywBase/tfywBase_add");
logger.info("类型信息:" + typeList);
//获得所有子类别
List<PageData> typeChildList = tfywBaseService.selectChildType();
mav.addObject("typeChildList",typeChildList);
logger.info("类型信息:" + typeChildList);
} catch (Exception e) {
e.printStackTrace();
}
return mav;
}
/**
* 删除
* @return
*/
@RequestMapping("/delete")
@ResponseBody
public JsonResult delete(){
PageData pageData = this.getPageData();
JsonResult result = new JsonResult();
try {
tfywBaseService.deleteMajor(pageData);
result.setMessage("删除成功");
} catch (Exception e) {
e.printStackTrace();
result.setState(JsonResult.ERROR);
result.setMessage("删除失败");
}
return result;
}
/**
* 查看详细
* @return
*/
@RequestMapping("/detail")
public ModelAndView showDetail(){
PageData pageData = this.getPageData();
ModelAndView mav = this.getModelAndView();
try {
//通过主键ID查看当前列的详细信息
TFYWBase tfywBase = tfywBaseService.selectOneById(pageData);
logger.info("tfywBase:" + tfywBase );
mav.addObject("tfywBase",tfywBase);
mav.addObject("separator",Const.SEPARATOR);
//给页面返回详情页面
mav.setViewName("tfywBase/tfywBase_detail");
} catch (Exception e) {
e.printStackTrace();
}
return mav;
}
/**
* 返回更新页面
* @return
*/
@RequestMapping("/show_update")
public ModelAndView showUpdate(){
ModelAndView mav = this.getModelAndView();
PageData pageData = this.getPageData();
try {
//通过主键ID查看当前列的详细信息
TFYWBase tfywBase = tfywBaseService.selectOneById(pageData);
mav.addObject("tfywBase",tfywBase);
//获得所有类别
List<PageData> typeList = tfywBaseService.selectAllType();
mav.addObject("typeList",typeList);
//获得所有子类别
List<PageData> typeChildList = tfywBaseService.selectChildType();
mav.addObject("typeChildList",typeChildList);
mav.addObject("separator",Const.SEPARATOR);
//给页面返回更新页面
mav.setViewName("tfywBase/tfywBase_update");
} catch (Exception e) {
e.printStackTrace();
}
return mav;
}
/**
* 点击增加按钮提交表单到这里,实现功能
* 相应文字信息保存数据库
* 图片文件名加后缀保存到数据库
*/
@RequestMapping(value="/add", method = RequestMethod.POST)
@ResponseBody
public ModelAndView save(HttpServletRequest req,String xz,Page page,
String title,String type_two,String show_lev,String worktime,String gjz,String sfcy,String blck,String sfzpyc,String sfxcbl,String sfwsbl,
@RequestParam MultipartFile log) throws Exception{
//获得本项目在Tomcat的路径
String path = req.getServletContext().getRealPath("/");
System.out.println("path+path+path"+req.getServletContext().getRealPath("/"));
//获取项目名
String webNameString = req.getServletContext().getContextPath();
System.out.println("webpath+webpath+webpath"+req.getServletContext().getContextPath());
//将FHMYSQL替换为updateFiles
path = path.replace(webNameString.substring(1), "updateFiles");
System.out.println("endpath+endpath+endpath"+path);
File dir=new File(path);
if(!dir.exists()){
dir.mkdir();
}
//一个图片文件处理,保存到服务器下,文件名保存到数据库
File file = null;
String newFileName="";
String logName="";
// 保存相对路径到数据库 图片写入服务器
if (log != null && !log.isEmpty()) {
// 获取图片的文件名
String fileName = log.getOriginalFilename();
// 获取图片的扩展名
String extensionName = fileName
.substring(fileName.lastIndexOf("."));
// 新的图片文件名 = 获取Uuid+"."图片扩展名
newFileName = UuidUtil.get32UUID()
+ extensionName;
file = new File(dir, newFileName);
log.transferTo(file);
}
logName = newFileName;
TFYWBase tfywBase = new TFYWBase();
tfywBase.setBase_id(this.get32UUID());
tfywBase.setTitle(title);
tfywBase.setCreatetime(DateUtil.getTime());
tfywBase.setShow_lev(Integer.valueOf(show_lev));
tfywBase.setWorktime(worktime);
tfywBase.setGjz(gjz);
tfywBase.setSfcy(sfcy);
tfywBase.setLog(logName);
tfywBase.setBlck(blck);
tfywBase.setSfzpyc(sfzpyc);
tfywBase.setSfxcbl(sfxcbl);
tfywBase.setSfwsbl(sfwsbl);
TypeSub typeSub = new TypeSub();
typeSub.setT_id(type_two);
tfywBase.setTypeSub(typeSub);
int success=tfywBaseService.insertMajor(tfywBase,xz,req);
//增加操作成功便跳转到列表页面
ModelAndView mav = this.getModelAndView();
if(success==1){
mav.addObject("msg","success");
String url = req.getContextPath()+"/tfywBase/list.do";
mav.setView(new RedirectView(url, false));
}else{
mav.addObject("msg","fail");
mav.setViewName("error");
}
return mav;
}
/**
* 点击更新按钮提交表单到这里,实现功能
* 相应文字信息保存数据库
* 图片文件名加后缀保存到数据库
*/
@RequestMapping(value="/update", method = RequestMethod.POST)
@ResponseBody
public ModelAndView update(HttpServletRequest req,String xz,Page page,
String base_id,String title,String type_two,String show_lev,String worktime,String gjz,String sfcy,String blck,String sfzpyc,String sfxcbl,String sfwsbl,
@RequestParam MultipartFile log) throws Exception{
//获得本项目在Tomcat的路径
String path = req.getServletContext().getRealPath("/");
//获取项目名
String webNameString = req.getServletContext().getContextPath();
//将FHMYSQL替换为uploadFiles
path = path.replace(webNameString.substring(1), "updateFiles");
File dir=new File(path);
if(!dir.exists()){
dir.mkdir();
}
//一个图片文件处理,保存到服务器下,文件名保存到数据库
File file = null;
String newFileName="";
String logName="";
// 保存相对路径到数据库 图片写入服务器
if (log != null && !log.isEmpty()) {
// 获取图片的文件名
String fileName = log.getOriginalFilename();
// 获取图片的扩展名
String extensionName = fileName
.substring(fileName.lastIndexOf("."));
// 新的图片文件名 = 获取Uuid+"."图片扩展名
newFileName = UuidUtil.get32UUID()
+ extensionName;
file = new File(dir, newFileName);
log.transferTo(file);
}
System.out.println(newFileName);
logName = newFileName;
TFYWBase tfywBase = new TFYWBase();
tfywBase.setBase_id(base_id);
tfywBase.setTitle(title);
tfywBase.setShow_lev(Integer.valueOf(show_lev));
tfywBase.setWorktime(worktime);
tfywBase.setGjz(gjz);
tfywBase.setSfcy(sfcy);
tfywBase.setLog(logName);
TypeSub typeSub = new TypeSub();
typeSub.setT_id(type_two);
tfywBase.setTypeSub(typeSub);
tfywBase.setBlck(blck);
tfywBase.setSfzpyc(sfzpyc);
tfywBase.setSfxcbl(sfxcbl);
tfywBase.setSfwsbl(sfwsbl);
int success=tfywBaseService.update(tfywBase,xz,req);
//更新操作成功便跳转到列表页面
ModelAndView mav = this.getModelAndView();
if(success==1){
mav.addObject("msg","success");
String url = req.getContextPath()+"/tfywBase/list.do";
mav.setView(new RedirectView(url, false));
}else{
mav.addObject("msg","fail");
mav.setViewName("error");
}
return mav;
}
/* ===============================权限================================== */
public Map<String, String> getHC(){
Subject currentUser = SecurityUtils.getSubject(); //shiro管理的session
Session session = currentUser.getSession();
return (Map<String, String>)session.getAttribute(Const.SESSION_QX);
}
/* ===============================权限================================== */
}
tfywBase_list.jsp(List列表是实体类EL表达式对应的实体类的属性名)
筛选功能通过page和pageData传值给后端筛选
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<!-- ace styles -->
<link rel="stylesheet" href="assets/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" />
<script src="assets/js/ace-extra.js"></script>
<!-- jsp文件头和头部 -->
<%@ include file="../system/admin/top.jsp"%>
</head>
<body>
<div class="container-fluid" id="main-container">
<div id="page-content" class="clearfix">
<div class="row-fluid">
<div class="row-fluid">
<!-- 检索 -->
<form method="post" id="listForm" action="tfywBase/list.do">
<table>
<tr>
<td style="vertical-align:top;">
<select id="selectState" name="selectState" >
<option value="-1">请选择二级类别</option>
<c:forEach items="${typeChildList}" var="typeChild">
<option value="${typeChild.T_ID}">${typeChild.TYPE_NAME}</option>
</c:forEach>
</select>
<input type="hidden" id="select" value="${page.pd.selectState}"/>
</td>
<td style="vertical-align:top;">
<span class="input-icon">
<input autocomplete="off" id="text" type="text" name="text" value="${page.pd.text}" placeholder="输入查询内容名"/>
<i class="icon-search"></i>
</span>
</td>
<td style="vertical-align:top;"><input class="date-picker" name="begin" id="begin" value="${page.pd.begin}" type="text" data-date-format="yyyy-mm-dd" maxlength="10" readonly="readonly" placeholder="开始时间" /></td>
<td style="vertical-align:top;"><input class="date-picker" name="end" id="end" value="${page.pd.end}" type="text" data-date-format="yyyy-mm-dd" maxlength="10" readonly="readonly" placeholder="结束时间" /></td>
<td style="vertical-align:top;"><button class="btn btn-mini btn-light" onclick="submitSearch();" title="检索"><i id="nav-search-icon" class="icon-search"></i></button></td>
</table>
<!-- 检索 -->
<table id="table_report" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>序号</th>
<th>标题</th>
<th>一级分类</th>
<th>二级分类</th>
<th>创建时间</th>
<th>热词优先度</th>
<!-- <th>办理时间</th> -->
<th>关键字</th>
<th>是否常用</th>
<th class="center">操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${tfywBaseList}" var="tfywBase" varStatus="vs">
<tr>
<td>${vs.count}</td>
<td>${tfywBase.title}</td>
<td>${tfywBase.typeSub.type.typeName}</td>
<td>${tfywBase.typeSub.type_name}</td>
<td>${tfywBase.createtime}</td>
<td>${tfywBase.show_lev}</td>
<%-- <td>${tfywBase.worktime}</td> --%>
<td>${tfywBase.gjz}</td>
<td>${tfywBase.sfcy}</td>
<td>
<input type="button" class="btn btn-primary" onclick="showDetail('${tfywBase.base_id}')" value="详细">
<input type="button" class="btn btn-default" onclick="update('${tfywBase.base_id}')" value="修改">
<input type="button" class="btn btn-danger" onclick="deleteById('${tfywBase.base_id}')" value="删除">
<input type="button" class="btn btn-danger" onclick="addDetail('${tfywBase.base_id}')" value="所需文件">
</td>
</tr>
</c:forEach>
</tbody>
</table>
<div class="page-header position-relative">
<table style="width:100%;">
<tr>
<td style="vertical-align:top;">
<a class="btn btn-small btn-success" onclick="add();">新增查询内容</a>
</td>
<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
</tr>
</table>
</div>
</form>
</div>
<!-- PAGE CONTENT ENDS HERE -->
</div><!--/row-->
</div><!--/#page-content-->
</div><!--/.fluid-container#main-container-->
<!-- 返回顶部 -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
<i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>
<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<!--[if lte IE 8]>
<link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<script src="assets/js/html5shiv.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
<script type="text/javascript">
$(function() {
top.hangge()
//日期框
$('.date-picker').datepicker();
//下拉框
$(".chzn-select").chosen();
$(".chzn-select-deselect").chosen({allow_single_deselect:true});
var select = $("#select").val();
$("#selectState option[value='"+select+"']").attr("selected","selected");
});
//新增项目
function add(){
top.jzts();
$.ajax({
type: 'get',
url: '<%=basePath%>tfywBase/add_show.do',
dataType: 'html',
success: function (result) {
$('#page-content').html(result);
top.hangge();
}
});
}
function deleteById(id){
top.jzts();
$.ajax({
type: 'get',
url: 'tfywBase/delete.do',
data : {
"id": id
},
success: function(result){
alert(result.message);
window.location = '<%=basePath%>tfywBase/list.do';
},
error: function(result){
alert(result.message);
top.hangge();
}
});
}
function showDetail(id) {
top.jzts();
$.ajax({
type: 'get',
url: 'tfywBase/detail.do',
data: {
"id": id
},
dataType: 'html',
success: function (result) {
$('#page-content').html(result);
top.hangge();
}
});
}
function addDetail(id) {
top.jzts();
$.ajax({
type: 'get',
url: 'tfywBase/addDetail.do',
data: {
"base_id": id
},
dataType: 'html',
success: function (result) {
$('#page-content').html(result);
top.hangge();
}
});
}
function update(id) {
top.jzts();
$.ajax({
type: 'get',
url: 'tfywBase/show_update.do',
data: {
"id": id
},
dataType: 'html',
success: function (result) {
$('#page-content').html(result);
top.hangge();
}
});
}
function submitSearch(){
var text = $('#text').val();
var begin = $('#begin').val();
var end = $('#end').val();
var selectState = $('#selectState').val();
$.ajax({
url: '<%=basePath%>tfywBase/list.do',
type: 'POST',
cache: false,
data: {text:text,begin:begin,end:end,selectState:selectState},
processData: true
});
}
</script>
</body>
</html>