HbuilderX的开发界面分成了三个独立的板块
附上sql语句写在idea的xml文件里的
<!--写页面的HTML代码-->
<template>
<view class="container">
<uni-nav-bar left-text="< 返回" right-text="主页" title="论文管理系统" backgroundColor="#d3233b" color="#ffffff" fixed="true" @clickLeft="doLeft" />
<uni-forms style="margin-top: 50rpx; margin-left: 50rpx;">
<uni-forms-item label="题目:" style="width: 400rpx; float: left; margin-right: 50rpx;">
<uni-easyinput v-model="title" placeholder="请输入题目"></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="类型:" style="width: 400rpx; float: left; margin-right: 50rpx;">
<uni-data-select
v-model="type"
:localdata="range"
@change="change"
></uni-data-select>
</uni-forms-item>
<uni-forms-item>
<button type="default" size="mini" style="margin-right: 15rpx;" @click="doSearch">查询</button>
<button type="default" size="mini" @click="doAdd">添加</button>
</uni-forms-item>
</uni-forms>
<uni-table stripe border>
<uni-tr>
<uni-th align="center">编号</uni-th>
<uni-th align="center">题目</uni-th>
<uni-th align="center">作者</uni-th>
<uni-th align="center">论文类型</uni-th>
<uni-th align="center">状态</uni-th>
<uni-th align="center">发布时间</uni-th>
<uni-th align="center">评论次数</uni-th>
<uni-th align="center">操作</uni-th>
</uni-tr>
<uni-tr v-for="p in paperList">
<uni-td>{{p.id}}</uni-td>
<uni-td>{{p.title}}</uni-td>
<uni-td>{{p.author}}</uni-td>
<uni-td>{{p.paperType}}</uni-td>
<uni-td>{{p.state==0 ? '未发布':'已发布'}}</uni-td>
<uni-td>{{p.publishDate}}</uni-td>
<uni-td>{{p.cnt}}</uni-td>
<uni-td align="center">
<button type="primary" size="mini" style="margin-right: 10rpx;" @click="doUpdate(p.id)">修改</button>
<button type="warn" size="mini" @click="doDelete(p.id)">删除</button>
</uni-td>
</uni-tr>
</uni-table>
<uni-pagination style="margin-top: 30rpx;" :current="pageIndex" :page-size="pageSize" :total="pageTotle" @change="pageChanged"></uni-pagination>
<!-- 提示框 -->
<uni-popup ref="popup" type="dialog">
<uni-popup-dialog
mode="base" title="通知"
:content="msg"
:duration="2000"
:before-close="true"
@close="close"
@confirm="confirm">
</uni-popup-dialog>
</uni-popup>
</view>
</template>
<!--写业务代码,最常见的:发送网络请求-->
<script>
export default {
data() {
return {
msg: null,
paperList: null,
title: null,
type: null,
//分页相关
pageIndex: 1,
pageSize: 2,
pageTotle: 0,
range: [
{ value: "应用型", text: "应用型" },
{ value: "学术型", text: "学术型" }
]
}
},
methods: {
//分页器被点击后触发
pageChanged(p){
console.log(p)
this.pageIndex = p.current;
var url = 'http://localhost:8070/paper/find_all?title='+this.title+'&type='+this.type+'&pageIndex='+p.current+'&pageSize='+this.pageSize
this.requestPaperList(url);
},
//请求论文列表
requestPaperList(uri){
uni.request({
url: uri,
method: 'GET',
success: (res) => {
console.log(res.data);
this.paperList = res.data.data;
this.pageTotle = res.data.total;
}
})
},
doLeft(){
this.msg = "点击了返回按钮"
this.open();
},
open() {
this.$refs.popup.open()
},
/**
* 点击取消按钮触发
*/
close() {
this.$refs.popup.close()
},
/**
* 点击确认按钮触发
*/
confirm(value) {
this.$refs.popup.close()
},
doUpdate(id){
uni.redirectTo({
url: 'modify_paper?id='+id
});
},
doAdd(){
uni.redirectTo({
url: 'add_paper'
});
},
doSearch(){
this.pageIndex = 1;
var url = 'http://localhost:8070/paper/find_all?title='+this.title+'&type='+this.type+'&pageIndex='+this.pageIndex+'&pageSize='+this.pageSize
this.requestPaperList(url);
},
doDelete(id){
uni.request({
url: "http://localhost:8070/paper/remove?id="+id,
method: 'GET',
success: (res) => {
console.log(res.data);
if(res.data.code == 200){
this.pageIndex = 1;
var url = 'http://localhost:8070/paper/find_all?title='+this.title+'&type='+this.type+'&pageIndex='+this.pageIndex+'&pageSize='+this.pageSize
this.requestPaperList(url);
} else {
this.msg = res.data.msg;
this.open();
}
}
})
},
//下拉列表选择时触发
change(e){
console.log("e:", e);
}
},
//页面加载完成之后执行
onLoad() {
var url = 'http://localhost:8070/paper/find_all?title='+this.title+'&type='+this.type+'&pageIndex='+this.pageIndex+'&pageSize='+this.pageSize
this.requestPaperList(url);
}
}
</script>
<!--页面的效果-->
<style>
.container {
padding: 20px;
font-size: 14px;
line-height: 24px;
}
</style>
------------------------------------------------------------------------------------------------
<!--写页面的HTML代码-->
<template>
<view>
<uni-nav-bar left-text="< 返回" title="添加论文" backgroundColor="#d3233b" color="#ffffff" fixed="true" @clickLeft="doLeft" />
<!-- 提示框 -->
<uni-popup ref="popup" type="dialog">
<uni-popup-dialog
mode="base" title="通知"
:content="msg"
:duration="2000"
:before-close="true"
@close="close"
@confirm="confirm">
</uni-popup-dialog>
</uni-popup>
<uni-forms style="width: 500rpx;">
<uni-forms-item label="题目:">
<uni-easyinput v-model="paperTitle" placeholder="请输入题目"></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="作者:">
<uni-easyinput v-model="author" placeholder="请输入作者"></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="论文类型:">
<uni-data-select
v-model="paperType"
:localdata="paperListTemp"
@change="changeType"
></uni-data-select>
</uni-forms-item>
<uni-forms-item label="状态:">
<uni-data-select
v-model="paperState"
:localdata="stateTemp"
@change="changeState"
></uni-data-select>
</uni-forms-item>
<uni-forms-item>
<button size="mini" type="primary" @click="doAdd">添加论文</button>
</uni-forms-item>
</uni-forms>
</view>
</template>
<!--写业务代码,最常见的:发送网络请求-->
<script>
export default {
data() {
return {
msg: null,
paperTitle: null,
author: null,
paperType: null,
paperState: 0,
paperListTemp: [
{vale : '学术型', text: '学术型'},
{vale : '应用型', text: '应用型'}
],
stateTemp: [
{vale : 0, text: '未发表'},
{vale : 1, text: '已发表'}
]
}
},
methods: {
doLeft(){
this.msg = "点击了返回按钮"
this.open();
},
open() {
this.$refs.popup.open()
},
/**
* 点击取消按钮触发
*/
close() {
this.$refs.popup.close()
},
/**
* 点击确认按钮触发
*/
confirm(value) {
this.$refs.popup.close()
},
changeType(e){
this.paperType = e;
},
changeState(e){
this.paperState = e;
},
doAdd(){
uni.request({
url: 'http://localhost:8070/paper/save',
method: 'POST',
data: {
title: this.paperTitle,
author: this.author,
paperType: this.paperType,
state: this.paperState
},
success: (res) => {
console.log(res.data);
if(res.data.code == 200){
uni.redirectTo({
url: 'paper'
});
} else {
this.msg = res.data.msg;
this.open();
}
}
})
}
}
}
</script>
<!--页面的效果-->
<style>
</style>
------------------------------------------------------------------------------------------------
<!--写页面的HTML代码-->
<template>
<view>
<uni-nav-bar left-text="< 返回" title="修改论文" backgroundColor="#d3233b" color="#ffffff" fixed="true" @clickLeft="doLeft" />
<!-- 提示框 -->
<uni-popup ref="popup" type="dialog">
<uni-popup-dialog
mode="base" title="通知"
:content="msg"
:duration="2000"
:before-close="true"
@close="close"
@confirm="confirm">
</uni-popup-dialog>
</uni-popup>
<uni-forms style="width: 500rpx;">
<uni-forms-item label="题目:">
<uni-easyinput v-model="paperTitle" placeholder="请输入题目"></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="作者:">
<uni-easyinput v-model="author" placeholder="请输入作者"></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="论文类型:">
<uni-data-select
v-model="paperType"
:localdata="paperListTemp"
@change="changeType"
></uni-data-select>
</uni-forms-item>
<uni-forms-item label="状态:">
<uni-data-select
v-model="paperState"
:localdata="stateTemp"
@change="changeState"
></uni-data-select>
</uni-forms-item>
<uni-forms-item>
<button size="mini" type="primary" @click="doAdd">添加论文</button>
</uni-forms-item>
</uni-forms>
</view>
</template>
<!--写业务代码,最常见的:发送网络请求-->
<script>
export default {
data() {
return {
id: null,
msg: null,
paperTitle: null,
author: null,
paperType: null,
paperState: 0,
paperListTemp: [
{vale : '学术型', text: '学术型'},
{vale : '应用型', text: '应用型'}
],
stateTemp: [
{vale : 0, text: '未发表'},
{vale : 1, text: '已发表'}
]
}
},
onLoad(options) {
console.log("传来的id是:"+options.id)
this.id = options.id;
uni.request({
url: "http://localhost:8070/paper/find_by_id?id="+this.id,
method: 'GET',
success: (res) => {
console.log(res.data);
this.paperTitle = res.data.data.title;
this.paperState = res.data.data.state;
this.paperType = res.data.data.paperType;
this.author = res.data.data.author;
}
})
},
methods: {
doLeft(){
this.msg = "点击了返回按钮"
this.open();
},
open() {
this.$refs.popup.open()
},
/**
* 点击取消按钮触发
*/
close() {
this.$refs.popup.close()
},
/**
* 点击确认按钮触发
*/
confirm(value) {
this.$refs.popup.close()
},
changeType(e){
this.paperType = e;
},
changeState(e){
this.paperState = e;
},
doAdd(){
uni.request({
url: 'http://localhost:8070/paper/save',
method: 'POST',
data: {
title: this.paperTitle,
author: this.author,
paperType: this.paperType,
state: this.paperState
},
success: (res) => {
console.log(res.data);
if(res.data.code == 200){
uni.redirectTo({
url: 'paper'
});
} else {
this.msg = res.data.msg;
this.open();
}
}
})
}
}
}
</script>
<!--页面的效果-->
<style>
</style>
SQl语句用了where标签
<?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="demo.mapper.PaperMapper">
<select id="findAll" resultType="Paper">
SELECT
DISTINCT p.*, (SELECT count(*) FROM t_comment WHERE p_id=c.p_id) AS cnt
FROM
t_paper AS p LEFT JOIN t_comment AS c
ON
p.id=c.p_id
<where>
<if test="title !='null' and title != ''">
AND title like '%${title}%'
</if>
<if test="type !='null' and type != ''">
AND paper_type=#{type}
</if>
</where>
ORDER BY p.publish_date DESC
LIMIT #{pageIndex}, #{pageSize}
</select>
</mapper>