-
dependencies>
-
-
<dependency>
-
<groupId>org.mybatisgroupId>
-
<artifactId>mybatisartifactId>
-
<version>3.4.1version>
-
dependency>
-
-
<dependency>
-
<groupId>mysqlgroupId>
-
<artifactId>mysql-connector-javaartifactId>
-
<version>5.1.29version>
-
dependency>
-
-
<dependency>
-
<groupId>org.slf4jgroupId>
-
<artifactId>slf4j-log4j12artifactId>
-
<version>1.6.1version>
-
dependency>
-
<dependency>
-
<groupId>org.slf4jgroupId>
-
<artifactId>slf4j-apiartifactId>
-
<version>1.6.1version>
-
dependency>
-
-
<dependency>
-
<groupId>org.springframeworkgroupId>
-
<artifactId>spring-jdbcartifactId>
-
<version>4.3.11.RELEASEversion>
-
dependency>
-
-
<dependency>
-
<groupId>org.springframeworkgroupId>
-
<artifactId>spring-aspectsartifactId>
-
<version>4.3.11.RELEASEversion>
-
dependency>
-
<dependency>
-
<groupId>org.springframeworkgroupId>
-
<artifactId>spring-contextartifactId>
-
<version>4.3.11.RELEASEversion>
-
dependency>
-
-
<dependency>
-
<groupId>org.mybatisgroupId>
-
<artifactId>mybatis-springartifactId>
-
<version>1.3.1version>
-
dependency>
-
-
<dependency>
-
<groupId>org.springframeworkgroupId>
-
<artifactId>spring-webmvcartifactId>
-
<version>4.3.11.RELEASEversion>
-
dependency>
-
-
<dependency>
-
<groupId>jstlgroupId>
-
<artifactId>jstlartifactId>
-
<version>1.2version>
-
dependency>
-
-
<dependency>
-
<groupId>com.github.pagehelpergroupId>
-
<artifactId>pagehelperartifactId>
-
<version>4.2.1version>
-
dependency>
-
-
<dependency>
-
<groupId>com.fasterxml.jackson.coregroupId>
-
<artifactId>jackson-databindartifactId>
-
<version>2.7.4version>
-
dependency>
-
-
<dependency>
-
<groupId>commons-fileuploadgroupId>
-
<artifactId>commons-fileuploadartifactId>
-
<version>1.3.3version>
-
dependency>
-
dependencies>
-
-
-
<build>
-
<finalName>ssm-blog-adminfinalName>
-
-
-
<resources>
-
-
-
<resource>
-
<directory>src/main/javadirectory>
-
<includes>
-
<include>**/*.xmlinclude>
-
includes>
-
<filtering>truefiltering>
-
resource>
-
<resource>
-
-
<directory>src/main/resourcesdirectory>
-
-
<includes>
-
<include>**/*.xmlinclude>
-
<include>**/*.propertiesinclude>
-
includes>
-
resource>
-
resources>
-
build>
实体类pojo
Diary.java
-
public class Diary {
-
private Integer id; //主键ID
-
private Integer userId; //用户ID
-
private Date createdDate; //日记创建时间
-
private String content; //日记内容
-
private String title; //日记标题
-
private int status; //身份权限,1:有效,0:无效
-
private String nickname; //昵称
-
private AdminUser adminUser; //管理员
-
-
public Integer getId() {
-
return id;
-
}
-
-
public void setId(Integer id) {
-
this.id = id;
-
}
-
-
public Integer getUserId() {
-
return userId;
-
}
-
-
public void setUserId(Integer userId) {
-
this.userId = userId;
-
}
-
-
public Date getCreatedDate() {
-
return createdDate;
-
}
-
-
public void setCreatedDate(Date createdDate) {
-
this.createdDate = createdDate;
-
}
-
-
public String getContent() {
-
return content;
-
}
-
-
public void setContent(String content) {
-
this.content = content;
-
}
-
-
public String getTitle() {
-
return title;
-
}
-
-
public void setTitle(String title) {
-
this.title = title;
-
}
-
-
public int getStatus() {
-
return status;
-
}
-
-
public void setStatus(int status) {
-
this.status = status;
-
}
-
-
public String getNickname() {
-
return nickname;
-
}
-
-
public void setNickname(String nickname) {
-
this.nickname = nickname;
-
}
-
-
public AdminUser getAdminUser() {
-
return adminUser;
-
}
-
-
public void setAdminUser(AdminUser adminUser) {
-
this.adminUser = adminUser;
-
}
-
}
DAO层
DiaryDAO.java
-
public interface DiaryDAO {
-
//插入日记方法
-
void addDiary(Diary diary);
-
//查询日记列表
-
List
getDiaryList(Diary diary); -
//根据id查询日记
-
Diary getDiaryById(int id);
-
//更新日记
-
void updateDiary(Diary diary);
-
//更新用户权限
-
void updateDiaryStatus(Diary diary);
-
}
DiaryMapper.xml
-
-
-
-
-
-
<mapper namespace="com.ssm.blog.dao.DiaryDAO">
-
-
-
<insert id="addDiary" parameterType="Diary">
-
INSERT INTO diary(USER_ID,CREATED_DATE,CONTENT,TITLE,STATUS)
-
VALUES (#{userId},now(),#{content},#{title},#{status})
-
insert>
-
-
-
<resultMap id="diaryMap" type="Diary">
-
-
<id property="id" column="ID"/>
-
<result property="userId" column="USER_ID"/>
-
<result property="createdDate" column="CREATED_DATE"/>
-
<result property="content" column="CONTENT"/>
-
<result property="title" column="TITLE"/>
-
<result property="status" column="STATUS"/>
-
resultMap>
-
-
<select id="getDiaryList" parameterType="Diary" resultMap="diaryMap">
-
SELECT D.ID,D.TITLE,D.USER_ID,D.CREATED_DATE,D.CONTENT,D.STATUS,A.NICKNAME
-
FROM diary D
-
INNER JOIN ADMIN_USER A ON D.USER_ID=A.ID
-
<where>
-
<if test="id !=null">D.ID=#{id}if>
-
<if test="title !=null and title!=''">and TITLE like concat('%',#{title},'%')if>
-
<if test="nickname !=null and nickname!=''">and NICKNAME like concat('%',#{nickname},'%')if>
-
where>
-
select>
-
-
-
-
<select id="getDiaryById" parameterType="int" resultMap="diaryMap">
-
SELECT ID,TITLE,CONTENT,STATUS
-
FROM Diary
-
WHERE ID=#{id}
-
select>
-
-
-
<update id="updateDiary" parameterType="Diary">
-
update diary set TITLE=#{title},CONTENT=#{content},STATUS=#{status}
-
where ID=#{id}
-
update>
-
-
-
-
<update id="updateDiaryStatus" parameterType="Diary">
-
update diary set STATUS=0
-
where ID=#{id}
-
update>
-
mapper>
service层
DiaryService.java
-
public interface DiaryService {
-
//插入日记
-
void addDiary(Diary diary);
-
-
//查询日记列表并分页
-
PageInfo
getDiaryList(Diary diary,int pageNum,int pageSize); -
-
//根据id查询,用于回显
-
Diary getDiaryById(Integer id);
-
-
//更新日记
-
void updateDiary(Diary diary);
-
//更改权限
-
void updateDiaryStatus(int id);
-
}
service层 DiarySrviceImpl.java
-
//加service注解
-
-
public class DiaryServiceImpl implements DiaryService {
-
// 当Spring发现@Autowired注解时,将自动在代码上下文中找到和其匹配(默认是类型匹配)的Bean,
-
// 并自动注入到相应的地方去。
-
-
private DiaryDAO diaryDAO;
-
-
//插入日记
-
-
public void addDiary(Diary diary) {
-
diaryDAO.addDiary(diary);
-
}
-
//查询日记列表并分页
-
-
public PageInfo
getDiaryList(Diary diary, int pageNum, int pageSize) { -
PageHelper.startPage(pageNum, pageSize);
-
List
diaryList = diaryDAO.getDiaryList(diary); -
PageInfo
pageInfo = new PageInfo<>(diaryList); -
return pageInfo;
-
}
-
//根据id查询日记
-
-
public Diary getDiaryById(Integer id) {
-
return diaryDAO.getDiaryById(id);
-
}
-
//更新日记
-
-
public void updateDiary(Diary diary) {
-
diaryDAO.updateDiary(diary);
-
}
-
//更新身份权限
-
-
public void updateDiaryStatus(int id) {
-
Diary diary = diaryDAO.getDiaryById(id);
-
-
diaryDAO.updateDiaryStatus(diary);
-
}
-
}
-
controller层
DiaryController.java
-
//加controller注解,处理由DispatcherServlet分发的请求
-
-
//定义url
-
-
public class DiaryController {
-
-
private DiaryService diaryService;
-
-
-
-
//添加和修改,一个方法实现两个功能
-
public Map
edit(Diary diary){ -
if (diary.getId() == null) {
-
//从session中获取user的信息,后面写完登录再改
-
diary.setUserId( 2);
-
diaryService.addDiary(diary);
-
} else{
-
//修改
-
diaryService.updateDiary(diary);
-
}
-
return JsonUtils.getSuccessMessage("编辑成功",null);
-
}
-
-
//查询日记列表并分页
-
-
-
public Map
list(Diary diary, int page, int rows){ -
PageInfo
pageInfo = diaryService.getDiaryList(diary, page, rows); -
return JsonUtils.getDatagridPagerResult(pageInfo.getTotal(),pageInfo.getList());
-
}
-
-
//根据id查询所有,用于点击修改后回显
-
-
public ModelAndView getDiary(Integer id){
-
Diary diary = null;
-
if (id!=null){
-
diary = diaryService.getDiaryById(id);
-
}
-
return new ModelAndView("diary_edit","diary",diary);
-
}
-
-
//文件上传
-
-
private String DIARY_IMAGE_DIR;
-
-
private String DIARY_IMAGE_URL;
-
-
-
-
public String upload(MultipartFile file) {
-
return JsonUtils.fileUpload(file,DIARY_IMAGE_DIR,DIARY_IMAGE_URL);
-
}
-
-
//删除(修改权限)
-
-
-
public Map
delete(int id){ -
Diary diary = diaryService.getDiaryById(id);
-
if (diary.getStatus()!=0){
-
diaryService.updateDiaryStatus(id);
-
}
-
return JsonUtils.getSuccessMessage("删除权限成功",null);
-
}
-
}
util工具类
JsonUtils.java
-
public class JsonUtils {
-
public static Map
getSuccessMessage(String message,Object other){ -
Map
result = new HashMap<>(); -
result.put( "status", true);
-
result.put( "message", "添加成功");
-
result.put( "other",other);
-
return result;
-
}
-
-
public static Map
getErrorMessage(String message,Object other){ -
Map
result = new HashMap<>(); -
result.put( "status", false);
-
result.put( "message", "添加成功");
-
result.put( "other",other);
-
return result;
-
}
-
-
public static Map
getDatagridPagerResult(long total, List list){ -
Map
result = new HashMap<>(); -
result.put( "total",total); //总条数
-
result.put( "rows",list); //返回的list数据
-
return result;
-
}
-
-
public static String fileUpload(MultipartFile file,String DIR,String URL){
-
String oldFileName = file.getOriginalFilename();
-
String extName = oldFileName.substring(oldFileName.lastIndexOf( "."));
-
String newFileName = System.currentTimeMillis()+extName;
-
try {
-
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(DIR,newFileName));
-
return "{\"error\":0,\"url\":\"" + URL + newFileName + "\"}";
-
} catch (IOException e) {
-
e.printStackTrace();
-
return "{\"error\":1}";
-
}
-
}
-
}
resource
db.properties:配置mysql
-
jdbc.driver=com.mysql.jdbc.Driver
-
jdbc.url=jdbc:mysql://localhost:3306/personal_blog?characterEncoding=utf-8
-
jdbc.username=root
-
jdbc.password=123456
log4j.properties:输出日志信息
-
log4j.rootLogger=DEBUG, stdout
-
-
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
-
-
#begin
-
#for normal test,delete when online
-
log4j.logger.com.ibatis=DEBUG
-
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
-
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
-
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
-
-
log4j.logger.java.sql.Connection=DEBUG
-
log4j.logger.java.sql.Statement=DEBUG
-
log4j.logger.java.sql.PreparedStatement=DEBUG
-
log4j.logger.java.sql.ResultSet=DEBUG
resourse.properties:配置文件上传路径和url地址
-
DIARY_IMAGE_DIR=E:/upload/diary/
-
-
DIARY_IMAGE_URL=http://localhost:8080/upload/diary/
spring-config.xml
-
-
<context:property-placeholder location="classpath:db.properties" ignore-unresolvable="true"/>
-
-
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
-
<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>
-
-
-
<context:component-scan base-package="com.ssm.blog.*">
-
-
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
-
context:component-scan>
-
-
-
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
-
<property name="dataSource" ref="dataSource"/>
-
<property name="mapperLocations" value="classpath:com/ssm/blog/dao/mapper/*.xml"/>
-
<property name="typeAliasesPackage" value="com.ssm.blog.pojo"/>
-
<property name="plugins">
-
<array>
-
<bean class="com.github.pagehelper.PageHelper">
-
<property name="properties">
-
<value>
-
dialect=mysql
-
reasonable=true
-
value>
-
property>
-
bean>
-
array>
-
property>
-
bean>
-
-
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
-
<property name="basePackage" value="com.ssm.blog.dao"/>
-
bean>
-
-
<bean id="transactionManager"
-
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
-
<property name="dataSource" ref="dataSource"/>
-
bean>
-
-
<tx:advice id="txAdvice" transaction-manager="transactionManager">
-
<tx:attributes>
-
-
<tx:method name="add*" rollback-for="Exception"/>
-
<tx:method name="delete*" rollback-for="Exception"/>
-
<tx:method name="update*" rollback-for="Exception"/>
-
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
-
<tx:method name="do*" rollback-for="Exception"/>
-
tx:attributes>
-
tx:advice>
-
-
<aop:config>
-
<aop:pointcut id="serviceMethod"
-
expression="execution(* com.ssm.blog.service..*(..))"/>
-
<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"/>
-
aop:config>
WEB-INF
springMVC-servlet.xml
-
-
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManagerFactoryBean"/>
-
-
<context:component-scan base-package="com.ssm.blog.controller">
-
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
-
context:component-scan>
-
-
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
-
<property name="prefix" value="/">property>
-
<property name="suffix" value=".jsp">property>
-
bean>
-
-
<mvc:resources mapping="/media/**" location="/media/"/>
-
-
<bean id="contentNegotiationManagerFactoryBean"
-
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
-
<property name="favorPathExtension" value="false"/>
-
<property name="favorParameter" value="false"/>
-
<property name="ignoreAcceptHeader" value="false"/>
-
<property name="mediaTypes">
-
<map>
-
<entry key="json" value="application/json"/>
-
map>
-
property>
-
bean>
-
-
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
-
<property name="maxUploadSize" value="1048576"/>
-
<property name="defaultEncoding" value="UTF-8"/>
-
<property name="resolveLazily" value="true"/>
-
bean>
web.xml
-
-
<context-param>
-
<param-name>contextConfigLocationparam-name>
-
<param-value>classpath:spring-config.xmlparam-value>
-
context-param>
-
-
<listener>
-
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
-
listener>
-
<filter>
-
<filter-name>CharacterEncodingFilterfilter-name>
-
<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
-
<init-param>
-
<param-name>encodingparam-name>
-
<param-value>UTF-8param-value>
-
init-param>
-
<init-param>
-
<param-name>forceEncodingparam-name>
-
<param-value>trueparam-value>
-
init-param>
-
filter>
-
<filter-mapping>
-
<filter-name>CharacterEncodingFilterfilter-name>
-
<url-pattern>/*url-pattern>
-
filter-mapping>
-
-
<servlet>
-
<servlet-name>springMVCservlet-name>
-
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
-
servlet>
-
<servlet-mapping>
-
<servlet-name>springMVCservlet-name>
-
<url-pattern>*.htmlurl-pattern>
-
servlet-mapping>
-
<welcome-file-list>
-
<welcome-file>/blog/list.htmlwelcome-file>
-
welcome-file-list>
diary_list.jsp
-
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
-
<%--panel面板可以设置整体的高度--%>
-
<div class="easyui-panel" style="height: 95%">
-
<table id="diary-datagrid" style="height:450px">
-
table>
-
<div id="diary-datagrid-toolbar">
-
<div>
-
ID: <input type="text" class="easyui-numberbox" id="search-diary-id"/>
-
标题: <input type="text" id="search-diary-title"/>
-
昵称: <input type="text" id="search-diary-nickname"/>
-
<a href="#" class="easyui-linkbutton" iconCls="icon-search"
-
ο nclick="doDiarySearch()">搜索a>
-
div>
-
<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" οnclick="doEditDiary(0)">新增a>
-
<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" οnclick="doEditDiary(1)">修改a>
-
<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" οnclick="doDeleteDiary()">删除权限a>
-
div>
-
div>
-
-
<div class="easyui-dialog" closed="true" id="edit-diary-dialog"
-
modal="true" title="编辑日记" style="width:800px;height:600px;padding:30px" buttons="#dlg-diary-buttons">
-
div>
-
<div id="dlg-diary-buttons">
-
<a href="javascript:void(0)" class="easyui-linkbutton" οnclick="submitDiary()">保存a>
-
<a href="javascript:void(0)" class="easyui-linkbutton" οnclick="$('#edit-diary-form').form('reset');">重填a>
-
div>
-
<link href="<%=request.getContextPath()%>/media/kindeditor-4.1.10/themes/default/default.css" type="text/css"
-
rel="stylesheet">
-
<script type="text/javascript" charset="utf-8"
-
src="<%=request.getContextPath()%>/media/kindeditor-4.1.10/kindeditor-all.js">script>
-
<script type="text/javascript" charset="utf-8"
-
src="<%=request.getContextPath()%>/media/kindeditor-4.1.10/lang/zh_CN.js">script>
-
-
<script type="text/javascript">
-
$( function () {
-
$( "#diary-datagrid").datagrid({
-
url: "<%=request.getContextPath()%>/diary.html?act=list",
-
pagination: true,
-
pageList: [5, 10, 15, 20],
-
toolbar: "#diary-datagrid-toolbar",
-
frozen: true,//冻结标题行
-
singleSelect:true,
-
fit: true,//让表格自动适应面板的高度
-
nowrap: false,//高度自适应,当内容比较多的时候会自动换行
-
columns: [[
-
{ field: 'id', title: 'ID', width: 80},
-
{ field: 'title', title: '标题', width: 80},
-
{ field: 'createdDate', title: '发布时间', width: 160},
-
{ field: 'nickname', title: '作者', width: 80},
-
{
-
field: 'status', title: '身份权限', width: 80, formatter: function (val, row) {
-
if (row.status == 0) return "无效";
-
return row.status
-
}
-
}
-
]]
-
})
-
})
-
-
function doDiarySearch() {
-
var queryParams = $('#diary-datagrid').datagrid('options').queryParams;
-
queryParams.id = $( "#search-diary-id").val();
-
queryParams.title = $( "#search-diary-title").val();
-
queryParams.nickname = $( "#search-diary-nickname").val();
-
//重新加载datagrid
-
$( "#diary-datagrid").datagrid('reload');
-
}
-
-
var kingEditorParams = {
-
filePostName: "file",//指定上传文件参数名称
-
uploadJson: '<%=request.getContextPath()%>/diary.html?act=upload',//指定上传文件请求的url。
-
dir: "image"//上传类型,分别为image、flash、media、file,
-
}
-
var editor;
-
-
function doEditDiary(type) {
-
var id = "";
-
var row = $('#diary-datagrid').datagrid('getSelected'); //单选
-
if (type == 1) {//要修改
-
if (row == null) {
-
alert( "请选择要编辑的数据");
-
return;
-
}
-
id = row.id;
-
}
-
$( "#edit-diary-dialog").dialog({
-
href: "<%=request.getContextPath()%>/diary.html?act=get&id=" + id,
-
onLoad: function () {
-
editor = KindEditor.create($( "#editor"), kingEditorParams);
-
},
-
onBeforeDestroy: function () {
-
KindEditor.remove( "#editor");
-
}
-
}).dialog( 'open');
-
}
-
-
function submitDiary() {
-
$( '#edit-diary-form').form('submit', {
-
onSubmit: function () {
-
if ($(this).form('enableValidation').form('validate')) {
-
editor.sync(); //同步富文本编辑器,否则拿不到
-
$.ajax({
-
url: "<%=request.getContextPath()%>/diary.html?act=edit",
-
data: $("#edit-diary-form").serialize(),
-
method: "post",
-
success: function (data) {
-
if (data.status) {
-
$( "#diary-datagrid").datagrid('reload');
-
$( "#edit-diary-dialog").dialog("close");
-
} else {
-
alert(data.message)
-
}
-
}
-
})
-
}
-
return false;
-
}
-
});
-
}
-
-
function doDeleteDiary() {
-
var row = $('#diary-datagrid').datagrid('getSelected');
-
if (row == null){
-
return;
-
}
-
if (confirm("确定要删除权限吗?")){
-
$.ajax({
-
url:"<%=request.getContextPath()%>/diary.html?act=delete",
-
data:"id=" + row.id,
-
method:"post",
-
success:function (data) {
-
if (data.status){
-
$( "#diary-datagrid").datagrid('reload');
-
} else{
-
alert(data.message)
-
}
-
}
-
})
-
}
-
}
-
-
script>
diary_edit.jsp
-
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
-
<%--panel面板可以设置整体的高度--%>
-
<div class="easyui-panel" style="height: 95%">
-
<table id="diary-datagrid" style="height:450px">
-
table>
-
<div id="diary-datagrid-toolbar">
-
<div>
-
ID: <input type="text" class="easyui-numberbox" id="search-diary-id"/>
-
标题: <input type="text" id="search-diary-title"/>
-
昵称: <input type="text" id="search-diary-nickname"/>
-
<a href="#" class="easyui-linkbutton" iconCls="icon-search"
-
ο nclick="doDiarySearch()">搜索a>
-
div>
-
<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" οnclick="doEditDiary(0)">新增a>
-
<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" οnclick="doEditDiary(1)">修改a>
-
<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" οnclick="doDeleteDiary()">删除权限a>
-
div>
-
div>
-
-
<div class="easyui-dialog" closed="true" id="edit-diary-dialog"
-
modal="true" title="编辑日记" style="width:800px;height:600px;padding:30px" buttons="#dlg-diary-buttons">
-
div>
-
<div id="dlg-diary-buttons">
-
<a href="javascript:void(0)" class="easyui-linkbutton" οnclick="submitDiary()">保存a>
-
<a href="javascript:void(0)" class="easyui-linkbutton" οnclick="$('#edit-diary-form').form('reset');">重填a>
-
div>
-
<link href="<%=request.getContextPath()%>/media/kindeditor-4.1.10/themes/default/default.css" type="text/css"
-
rel="stylesheet">
-
<script type="text/javascript" charset="utf-8"
-
src="<%=request.getContextPath()%>/media/kindeditor-4.1.10/kindeditor-all.js">script>
-
<script type="text/javascript" charset="utf-8"
-
src="<%=request.getContextPath()%>/media/kindeditor-4.1.10/lang/zh_CN.js">script>
-
-
<script type="text/javascript">
-
$( function () {
-
$( "#diary-datagrid").datagrid({
-
url: "<%=request.getContextPath()%>/diary.html?act=list",
-
pagination: true,
-
pageList: [5, 10, 15, 20],
-
toolbar: "#diary-datagrid-toolbar",
-
frozen: true,//冻结标题行
-
singleSelect:true,
-
fit: true,//让表格自动适应面板的高度
-
nowrap: false,//高度自适应,当内容比较多的时候会自动换行
-
columns: [[
-
{ field: 'id', title: 'ID', width: 80},
-
{ field: 'title', title: '标题', width: 80},
-
{ field: 'createdDate', title: '发布时间', width: 160},
-
{ field: 'nickname', title: '作者', width: 80},
-
{
-
field: 'status', title: '身份权限', width: 80, formatter: function (val, row) {
-
if (row.status == 0) return "无效";
-
return row.status
-
}
-
}
-
]]
-
})
-
})
-
-
function doDiarySearch() {
-
var queryParams = $('#diary-datagrid').datagrid('options').queryParams;
-
queryParams.id = $( "#search-diary-id").val();
-
queryParams.title = $( "#search-diary-title").val();
-
queryParams.nickname = $( "#search-diary-nickname").val();
-
//重新加载datagrid
-
$( "#diary-datagrid").datagrid('reload');
-
}
-
-
var kingEditorParams = {
-
filePostName: "file",//指定上传文件参数名称
-
uploadJson: '<%=request.getContextPath()%>/diary.html?act=upload',//指定上传文件请求的url。
-
dir: "image"//上传类型,分别为image、flash、media、file,
-
}
-
var editor;
-
-
function doEditDiary(type) {
-
var id = "";
-
var row = $('#diary-datagrid').datagrid('getSelected'); //单选
-
if (type == 1) {//要修改
-
if (row == null) {
-
alert( "请选择要编辑的数据");
-
return;
-
}
-
id = row.id;
-
}
-
$( "#edit-diary-dialog").dialog({
-
href: "<%=request.getContextPath()%>/diary.html?act=get&id=" + id,
-
onLoad: function () {
-
editor = KindEditor.create($( "#editor"), kingEditorParams);
-
},
-
onBeforeDestroy: function () {
-
KindEditor.remove( "#editor");
-
}
-
}).dialog( 'open');
-
}
-
-
function submitDiary() {
-
$( '#edit-diary-form').form('submit', {
-
onSubmit: function () {
-
if ($(this).form('enableValidation').form('validate')) {
-
editor.sync(); //同步富文本编辑器,否则拿不到
-
$.ajax({
-
url: "<%=request.getContextPath()%>/diary.html?act=edit",
-
data: $("#edit-diary-form").serialize(),
-
method: "post",
-
success: function (data) {
-
if (data.status) {
-
$( "#diary-datagrid").datagrid('reload');
-
$( "#edit-diary-dialog").dialog("close");
-
} else {
-
alert(data.message)
-
}
-
}
-
})
-
}
-
return false;
-
}
-
});
-
}
-
-
function doDeleteDiary() {
-
var row = $('#diary-datagrid').datagrid('getSelected');
-
if (row == null){
-
return;
-
}
-
if (confirm("确定要删除权限吗?")){
-
$.ajax({
-
url:"<%=request.getContextPath()%>/diary.html?act=delete",
-
data:"id=" + row.id,
-
method:"post",
-
success:function (data) {
-
if (data.status){
-
$( "#diary-datagrid").datagrid('reload');
-
} else{
-
alert(data.message)
-
}
-
}
-
})
-
}
-
}
-
-
script>