This commit is contained in:
20932067@zju.edu.cn 2021-01-22 23:35:32 +08:00
parent 8473e7a4e4
commit 4db542232c
11 changed files with 462 additions and 237 deletions

View File

@ -98,6 +98,11 @@
<el-table-column label="学生姓名" align="center" prop="name" />
<el-table-column label="电话" align="center" prop="tel" />
<el-table-column label="电子邮件" align="center" prop="email" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
@ -117,7 +122,7 @@
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
@ -138,6 +143,24 @@
<el-form-item label="电子邮件" prop="email">
<el-input v-model="form.email" placeholder="请输入电子邮件" />
</el-form-item>
<el-divider content-position="center">成绩信息</el-divider>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddResults">添加</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteResults">删除</el-button>
</el-col>
</el-row>
<el-table :data="resultsList" :row-class-name="rowResultsIndex" @selection-change="handleResultsSelectionChange" ref="results">
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="序号" align="center" prop="index" width="50"/>
<el-table-column label="java成绩" prop="java">
<template slot-scope="scope">
<el-input v-model="scope.row.java" placeholder="请输入java成绩" />
</template>
</el-table-column>
</el-table>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
@ -148,150 +171,143 @@
</template>
<script>
import { listStu, getStu, delStu, addStu, updateStu, exportStu } from "@/api/test/stu";
import { listStu, getStu, delStu, addStu, updateStu, exportStu } from "@/api/test/stu";
export default {
name: "Stu",
components: {
},
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
stuList: [],
//
title: "",
//
open: false,
//
daterangeCreateTime: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
tel: null,
email: null,
createTime: null,
},
//
form: {},
//
rules: {
name: [
{ required: true, message: "学生姓名不能为空}", trigger: "blur" },
],
tel: [
{ required: true, message: "电话不能为空}", trigger: "blur" },
{ pattern: /^1[0-9]{10}$/, message: '电话格式有误', trigger:"blur"},
],
email: [
{ required: true, message: "电子邮件不能为空}", trigger: "blur" },
{ pattern: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, message: '电子邮件格式有误', trigger:"blur"},
],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询学生列表 */
getList() {
this.loading = true;
listStu(this.addCreateDateRange(this.queryParams,this.daterangeCreateTime)).then(response =>{
this.stuList = response.rows;
this.total = response.total;
this.loading = false;
});
export default {
name: "Stu",
components: {
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
name: null,
tel: null,
email: null,
createTime: null,
createBy: null,
updateTime: null,
updateBy: null
data() {
return {
//
loading: true,
//
ids: [],
//
checkedResults: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
stuList: [],
//
resultsList: [],
//
title: "",
//
open: false,
//
daterangeCreateTime: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
tel: null,
email: null,
},
//
form: {},
//
rules: {
}
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
created() {
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.daterangeCreateTime = [];
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加学生";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getStu(id).then(response => {
this.form = response.data;
methods: {
/** 查询学生列表 */
getList() {
this.loading = true;
listStu(this.addCreateDateRange(this.queryParams,this.daterangeCreateTime)).then(response =>{
this.stuList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
name: null,
tel: null,
email: null,
createBy: null,
updateBy: null
};
this.resultsList = [];
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.daterangeCreateTime = [];
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "修改学生";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateStu(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addStu(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
this.title = "添加学生";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getStu(id).then(response => {
this.form = response.data;
this.resultsList = response.data.resultsList;
this.open = true;
this.title = "修改学生";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
this.form.resultsList = this.resultsList;
if (this.form.id != null) {
updateStu(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addStu(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除学生编号为"' + ids + '"的数据项?', "警告", {
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除学生编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
@ -301,11 +317,38 @@ export default {
this.getList();
this.msgSuccess("删除成功");
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有学生数据项?', "警告", {
},
/** 成绩序号 */
rowResultsIndex({ row, rowIndex }) {
row.index = rowIndex + 1;
},
/** 成绩添加按钮操作 */
handleAddResults() {
let obj = {};
obj.java = "";
this.resultsList.push(obj);
},
/** 成绩删除按钮操作 */
handleDeleteResults() {
if (this.checkedResults.length == 0) {
this.$alert("请先选择要删除的成绩数据", "提示", { confirmButtonText: "确定", });
} else {
this.resultsList.splice(this.checkedResults[0].index - 1, 1);
}
},
/** 单选框选中数据 */
handleResultsSelectionChange(selection) {
if (selection.length > 1) {
this.$refs.results.clearSelection();
this.$refs.results.toggleRowSelection(selection.pop());
} else {
this.checkedResults = selection;
}
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有学生数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
@ -314,7 +357,7 @@ export default {
}).then(response => {
this.download(response.msg);
})
}
}
}
};
};
</script>

View File

@ -304,10 +304,10 @@ public class GenTableServiceImpl implements IGenTableService {
ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableName : tableNames) {
zip = generatorCode(tableName, zip);
generatorCode(tableName, zip);
// if (zip==null){
// return null;
// }
// generatorCode(tableName, zip);
if (zip==null){
return null;
}
}
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();

View File

@ -2,16 +2,13 @@ package ${packageName}.service.impl;
import java.util.List;
import com.hchyun.common.constant.ReturnConstants;
#foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.hchyun.common.utils.DateUtils;
#break
#end
#if($column.javaField == 'updateBy' || $column.javaField == 'createBy')
import com.hchyun.common.utils.SecurityUtils;
#break
#end
#end
import com.hchyun.common.utils.ServerResult;
@ -105,17 +102,18 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
#end
#end
#if($table.sub)
int rows = ${className}Dao.insert${ClassName}(${className});
insert${subClassName}(${className});
return rows;
int renewal = ${className}Dao.insert${ClassName}(${className});
if (insert${subClassName}(${className})){
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
}
#else
Integer renewal = ${className}Dao.insert${ClassName}(${className});
#end
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
}
#end
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
@ -136,15 +134,17 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
try {
#foreach ($column in $columns)
#if($column.javaField == 'updateTime')
${className}.setUpdateTime(DateUtils.getNowDate());
${className}.setUpdateTime(DateUtils.getNowDate());
#end
#if($column.javaField == 'updateBy')
${className}.setUpdateBy(SecurityUtils.getUserId());
${className}.setUpdateBy(SecurityUtils.getUserId());
#end
#end
#if($table.sub)
${className}Dao.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
insert${subClassName}(${className});
${className}Dao.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
if (insert${subClassName}(${className})){
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
}
#end
Integer renewal = ${className}Dao.update${ClassName}(${className});
if (renewal >0){
@ -171,7 +171,8 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
public ServerResult<Integer> delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) {
try {
#if($table.sub)
${className}Dao.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
//批量删除子表数据
${className}Dao.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
#end
Integer renewal = ${className}Dao.delete${ClassName}ByIds(${pkColumn.javaField}s);
if (renewal >0){
@ -195,6 +196,7 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
public ServerResult<Integer> delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) {
try {
#if($table.sub)
//删除子表数据
${className}Dao.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
#end
Integer renewal = ${className}Dao.delete${ClassName}ById(${pkColumn.javaField});
@ -215,23 +217,23 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
*
* @param ${className} ${functionName}对象
*/
public void insert${subClassName}(${ClassName} ${className})
{
public boolean insert${subClassName}(${ClassName} ${className}) {
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
if (StringUtils.isNotNull(${subclassName}List))
{
if (StringUtils.isNotNull(${subclassName}List)) {
List<${subClassName}> list = new ArrayList<${subClassName}>();
for (${subClassName} ${subclassName} : ${subclassName}List)
{
for (${subClassName} ${subclassName} : ${subclassName}List){
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
list.add(${subclassName});
}
if (list.size() > 0)
{
${className}Dao.batch${subClassName}(list);
if (list.size() > 0) {
Integer renewal = ${className}Dao.batch${subClassName}(list);
if (renewal>0){
return false;
}
}
}
return true;
}
#end
}

View File

@ -4,6 +4,9 @@ package ${packageName}.entity;
import ${import};
#end
import com.hchyun.common.annotation.Excel;
import com.hchyun.common.core.entity.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* ${subTable.functionName}对象 ${subTableName}

View File

@ -488,7 +488,7 @@ export default {
reset() {
this.form = {
#foreach ($column in $columns)
#if($column.htmlType != "datetime" && $column.queryType != "BETWEEN")
#if($column.htmlType != "datetime" && $column.queryType != "BETWEEN" && $column.javaField != 'createBy' && $column.javaField != 'updateBy')
#if($column.htmlType == "radio")
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end

View File

@ -126,9 +126,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<insert id="batch${subClassName}">
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($velocityCount != $subTable.columns.size()),#end#end) values
insert into ${subTableName}(#set($index = 0)#foreach($column in $subTable.columns)#if($column.isPk.equals("1"))#set($insex = 1)#else$column.columnName#if($velocityCount != ($subTable.columns.size()-$index)),#end#end#end) values
<foreach item="item" index="index" collection="list" separator=",">
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($velocityCount != $subTable.columns.size()),#end#end)
(#foreach($column in $subTable.columns)#if($column.isPk.equals("1"))#set($index = 1)#else#{item.$column.javaField}#if($velocityCount != $subTable.columns.size()),#end#end#end)
</foreach>
</insert>
#end

View File

@ -2,6 +2,7 @@ package com.hchyun.test.dao;
import java.util.List;
import com.hchyun.test.entity.Stu;
import com.hchyun.test.entity.Results;
/**
* 学生Mapper接口
@ -58,4 +59,29 @@ public interface StuDao
* @return 结果
*/
public int deleteStuByIds(Long[] ids);
/**
* 批量删除成绩
*
* @param customerIds 需要删除的数据ID
* @return 结果
*/
int deleteResultsByIds(Long[] ids);
/**
* 批量新增成绩
*
* @param resultsList 成绩列表
* @return 结果
*/
int batchResults(List<Results> resultsList);
/**
* 通过学生ID删除成绩信息
*
* @param roleId 角色ID
* @return 结果
*/
int deleteResultsBySId(Long id);
}

View File

@ -0,0 +1,65 @@
package com.hchyun.test.entity;
import com.hchyun.common.annotation.Excel;
import com.hchyun.common.core.entity.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 成绩对象 sys_results
*
* @author hchyun
* @date 2021-01-22
*/
public class Results extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** id */
private Long id;
/** 学生id */
@Excel(name = "学生id")
private Long sId;
/** java成绩 */
@Excel(name = "java成绩")
private Long java;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setSId(Long sId)
{
this.sId = sId;
}
public Long getSId()
{
return sId;
}
public void setJava(Long java)
{
this.java = java;
}
public Long getJava()
{
return java;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("sId", getSId())
.append("java", getJava())
.toString();
}
}

View File

@ -1,5 +1,6 @@
package com.hchyun.test.entity;
import java.util.List;
import com.hchyun.common.annotation.Excel;
import com.hchyun.common.core.entity.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
@ -30,6 +31,9 @@ public class Stu extends BaseEntity
@Excel(name = "电子邮件")
private String email;
/** 成绩信息 */
private List<Results> resultsList;
public void setId(Long id)
{
this.id = id;
@ -67,6 +71,16 @@ public class Stu extends BaseEntity
return email;
}
public List<Results> getResultsList()
{
return resultsList;
}
public void setResultsList(List<Results> resultsList)
{
this.resultsList = resultsList;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@ -78,6 +92,7 @@ public class Stu extends BaseEntity
.append("createBy", getCreateBy())
.append("updateTime", getUpdateTime())
.append("updateBy", getUpdateBy())
.append("resultsList", getResultsList())
.toString();
}
}

View File

@ -2,7 +2,6 @@ package com.hchyun.test.service.impl;
import java.util.List;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.utils.DateUtils;
import com.hchyun.common.utils.SecurityUtils;
@ -11,13 +10,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.hchyun.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.hchyun.test.entity.Results;
import com.hchyun.test.dao.StuDao;
import com.hchyun.test.entity.Stu;
import com.hchyun.test.service.StuService;
/**
* 学生Service业务层处理
*
*
* @author hchyun
* @date 2021-01-22
*/
@ -30,7 +34,7 @@ public class StuServiceImpl implements StuService {
/**
* 查询学生
*
*
* @param id 学生ID
* @return 学生
*/
@ -38,20 +42,20 @@ public class StuServiceImpl implements StuService {
public ServerResult<Stu> selectStuById(Long id) {
try {
Stu stu = stuDao.selectStuById(id);
if (stu != null){
return new ServerResult<Stu>(true,stu);
}else {
if (stu != null) {
return new ServerResult<Stu>(true, stu);
} else {
return new ServerResult<Stu>(false, ReturnConstants.RESULT_EMPTY);
}
}catch (RuntimeException e){
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<Stu>(false,ReturnConstants.DB_EX);
return new ServerResult<Stu>(false, ReturnConstants.DB_EX);
}
}
/**
* 查询学生列表
*
*
* @param stu 学生
* @return 学生
*/
@ -59,102 +63,138 @@ public class StuServiceImpl implements StuService {
public ServerResult<List<Stu>> selectStuList(Stu stu) {
try {
List<Stu> stuList = stuDao.selectStuList(stu);
if (stuList.size()>0){
return new ServerResult<List<Stu>>(true,stuList);
}else {
return new ServerResult<List<Stu>>(false,ReturnConstants.RESULT_EMPTY);
if (stuList.size() > 0) {
return new ServerResult<List<Stu>>(true, stuList);
} else {
return new ServerResult<List<Stu>>(false, ReturnConstants.RESULT_EMPTY);
}
}catch (RuntimeException e){
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<List<Stu>>(false,ReturnConstants.DB_EX);
return new ServerResult<List<Stu>>(false, ReturnConstants.DB_EX);
}
}
/**
* 新增学生
*
*
* @param stu 学生
* @return 结果
*/
@Transactional
@Override
public ServerResult<Integer> insertStu(Stu stu) {
try {
stu.setCreateTime(DateUtils.getNowDate());
stu.setCreateBy(SecurityUtils.getUserId());
Integer renewal = stuDao.insertStu(stu);
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
int rows = stuDao.insertStu(stu);
insertResults(stu);
if (rows > 0) {
return new ServerResult<Integer>(true, rows);
} else {
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
}
}catch (RuntimeException e){
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
}
}
/**
* 修改学生
*
*
* @param stu 学生
* @return 结果
*/
@Transactional
@Override
public ServerResult<Integer> updateStu(Stu stu) {
try {
stu.setUpdateTime(DateUtils.getNowDate());
stu.setUpdateBy(SecurityUtils.getUserId());
Integer renewal = stuDao.updateStu(stu);
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
stu.setUpdateTime(DateUtils.getNowDate());
stu.setUpdateBy(SecurityUtils.getUserId());
stuDao.deleteResultsBySId(stu.getId());
if (insertResults(stu)){
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
}
}catch (RuntimeException e){
Integer renewal = stuDao.updateStu(stu);
if (renewal > 0) {
return new ServerResult<Integer>(true, renewal);
} else {
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
}
}
/**
* 批量删除学生
*
*
* @param ids 需要删除的学生ID
* @return 结果
*/
@Transactional
@Override
public ServerResult<Integer> deleteStuByIds(Long[] ids) {
try {
//todo 批量删除子表数据
stuDao.deleteResultsByIds(ids);
Integer renewal = stuDao.deleteStuByIds(ids);
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
if (renewal > 0) {
return new ServerResult<Integer>(true, renewal);
} else {
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
}
}catch (RuntimeException e){
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
}
}
/**
* 删除学生信息
*
*
* @param id 学生ID
* @return 结果
*/
@Override
public ServerResult<Integer> deleteStuById(Long id) {
try {
//todo 删除子表数据
stuDao.deleteResultsBySId(id);
Integer renewal = stuDao.deleteStuById(id);
if (renewal >0){
return new ServerResult<Integer>(true,renewal);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
if (renewal > 0) {
return new ServerResult<Integer>(true, renewal);
} else {
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
}
}catch (RuntimeException e){
} catch (RuntimeException e) {
logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
}
}
/**
* 新增成绩信息
*
* @param stu 学生对象
*/
public boolean insertResults(Stu stu) {
List<Results> resultsList = stu.getResultsList();
Long id = stu.getId();
if (StringUtils.isNotNull(resultsList)) {
List<Results> list = new ArrayList<Results>();
for (Results results : resultsList) {
results.setSId(id);
list.add(results);
}
if (list.size() > 0) {
Integer renewal = stuDao.batchResults(list);
if (renewal>0){
return false;
}
}
}
return true;
}
}

View File

@ -1,9 +1,9 @@
<?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">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hchyun.test.dao.StuDao">
<resultMap type="Stu" id="StuResult">
<result property="id" column="id" />
<result property="name" column="name" />
@ -15,53 +15,66 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
</resultMap>
<resultMap id="StuResultsResult" type="Stu" extends="StuResult">
<collection property="resultsList" notNullColumn="id" javaType="java.util.List" resultMap="ResultsResult" />
</resultMap>
<resultMap type="Results" id="ResultsResult">
<result property="id" column="id" />
<result property="sId" column="s_id" />
<result property="java" column="java" />
</resultMap>
<sql id="selectStuVo">
select id, name, tel, email, create_time, create_by, update_time, update_by from sys_stu
</sql>
<select id="selectStuList" parameterType="Stu" resultMap="StuResult">
<include refid="selectStuVo"/>
<where>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="tel != null "> and tel like concat('%', #{tel}, '%')</if>
<if test="email != null and email != ''"> and email like concat('%', #{email}, '%')</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
</where>
</select>
<select id="selectStuById" parameterType="Long" resultMap="StuResult">
<include refid="selectStuVo"/>
where id = #{id}
<select id="selectStuById" parameterType="Long" resultMap="StuResultsResult">
select a.id, a.name, a.tel, a.email, a.create_time, a.create_by, a.update_time, a.update_by,
b.id, b.s_id, b.java
from sys_stu a
left join sys_results b on b.s_id = a.id
where a.id = #{id}
</select>
<insert id="insertStu" parameterType="Stu" useGeneratedKeys="true" keyProperty="id">
insert into sys_stu
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">name,</if>
<if test="name != null">name,</if>
<if test="tel != null">tel,</if>
<if test="email != null and email != ''">email,</if>
<if test="email != null">email,</if>
<if test="createTime != null">create_time,</if>
<if test="createBy != null">create_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="updateBy != null">update_by,</if>
</trim>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if>
<if test="name != null">#{name},</if>
<if test="tel != null">#{tel},</if>
<if test="email != null and email != ''">#{email},</if>
<if test="email != null">#{email},</if>
<if test="createTime != null">#{createTime},</if>
<if test="createBy != null">#{createBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="updateBy != null">#{updateBy},</if>
</trim>
</trim>
</insert>
<update id="updateStu" parameterType="Stu">
update sys_stu
<trim prefix="SET" suffixOverrides=",">
<if test="name != null and name != ''">name = #{name},</if>
<if test="name != null">name = #{name},</if>
<if test="tel != null">tel = #{tel},</if>
<if test="email != null and email != ''">email = #{email},</if>
<if test="email != null">email = #{email},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
@ -75,9 +88,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="deleteStuByIds" parameterType="String">
delete from sys_stu where id in
delete from sys_stu where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="deleteResultsBySIds" parameterType="String">
delete from sys_results where s_id in
<foreach item="sId" collection="array" open="(" separator="," close=")">
#{sId}
</foreach>
</delete>
<delete id="deleteResultsBySId" parameterType="Long">
delete from sys_results where s_id = #{sId}
</delete>
<insert id="batchResults">
insert into sys_results( s_id, java) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.sId}, #{item.java})
</foreach>
</insert>
</mapper>