修复用户信息修改页面数据绑定方式,改为使用axios进行数据获取和绑定

This commit is contained in:
F嘉阳
2018-02-23 10:49:55 +08:00
parent 3abbd49f65
commit c91ee252a3
7 changed files with 168 additions and 15 deletions

View File

@@ -9,8 +9,12 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
@RestController
public class DataController {
@@ -38,6 +42,9 @@ public class DataController {
@Autowired
private VUserfileService vUserfileService;
@Resource
HttpServletRequest httpServletRequest;
@GetMapping("/home/findAllHomework")
public List<VWorkDetail> findAllHomework(){
List<VWorkDetail> homeworks = workDetailService.findAll();
@@ -108,4 +115,10 @@ public class DataController {
new UserException(ResultEnum.EMPTY_DATA);
return null;
}
@GetMapping("/home/userinfo")
public VUserinfo findUserInfo(){
TbUser user= (TbUser)httpServletRequest.getSession().getAttribute(USER_SESSION_KEY);
return userService.findUserInfo(user.getColuserid());
}
}

View File

@@ -0,0 +1,74 @@
package com.fjy.spring.domain;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Subselect;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
@Immutable
@Subselect("SELECT * FROM v_userinfo")
public class VUserinfo {
@Id
private Integer coluserid;
private String colname;
private String colemail;
private String colstudentno;
private String colrealname;
public Integer getColuserid() {
return coluserid;
}
public void setColuserid(Integer coluserid) {
this.coluserid = coluserid;
}
public String getColname() {
return colname;
}
public void setColname(String colname) {
this.colname = colname;
}
public String getColemail() {
return colemail;
}
public void setColemail(String colemail) {
this.colemail = colemail;
}
public String getColstudentno() {
return colstudentno;
}
public void setColstudentno(String colstudentno) {
this.colstudentno = colstudentno;
}
public String getColrealname() {
return colrealname;
}
public void setColrealname(String colrealname) {
this.colrealname = colrealname;
}
@Override
public String toString() {
return "VUserinfo{" +
"coluserid=" + coluserid +
", colname='" + colname + '\'' +
", colemail='" + colemail + '\'' +
", colstudentno='" + colstudentno + '\'' +
", colrealname='" + colrealname + '\'' +
'}';
}
}

View File

@@ -6,7 +6,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/*@Configuration*/
@Configuration
public class WebAppConfig implements WebMvcConfigurer {
/**

View File

@@ -0,0 +1,8 @@
package com.fjy.spring.repository;
import com.fjy.spring.domain.VUserinfo;
import org.springframework.data.jpa.repository.JpaRepository;
public interface VUserinfoRepository extends JpaRepository<VUserinfo,Integer> {
}

View File

@@ -1,9 +1,11 @@
package com.fjy.spring.service;
import com.fjy.spring.domain.TbUser;
import com.fjy.spring.domain.VUserinfo;
import com.fjy.spring.enums.ResultEnum;
import com.fjy.spring.exception.UserException;
import com.fjy.spring.repository.TbUserRepository;
import com.fjy.spring.repository.VUserinfoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -16,6 +18,9 @@ public class UserService {
@Autowired
private TbUserRepository tbUserRepository;
@Autowired
private VUserinfoRepository vUserinfoRepository;
public TbUser doLoginService(String name,String password){
TbUser user = (TbUser)tbUserRepository.findByColname(name).get();
@@ -44,4 +49,8 @@ public class UserService {
return tbUserRepository.findAll();
}
public VUserinfo findUserInfo(Integer coluserid){
return vUserinfoRepository.findById(coluserid).get();
}
}

View File

@@ -14,6 +14,21 @@ function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2002-12-18格式
}
var Main = {
data() {
var checkName = (rule, value, callback) => {
if (!value) {
return callback(new Error('用户名不能为空'));
}
};
var checkNo = (rule, value, callback) => {
if (!value) {
return callback(new Error('学号不能为空'));
}
};
var checkRealName = (rule, value, callback) => {
if (!value) {
return callback(new Error('真实姓名不能为空'));
}
};
var validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入密码'));
@@ -34,7 +49,7 @@ var Main = {
}
};
return {
activeIndex: '1',
activeIndex: '2-1',
ruleForm2: {
coluserid:'',
colname: '',
@@ -45,9 +60,29 @@ var Main = {
checkPass: '',
},
rules2: {
colpassword: [
{required: true,validator: validatePass, trigger: 'blur'}
],
checkPass: [
{ validator: validatePass2, trigger: 'blur'}
]
{required: true,validator: validatePass2, trigger: 'blur'}
],
colstudentno: [
{
required: true,
validator: checkNo,
trigger: 'blur'
}
],
colrealname: [
{
required: true,
validator: checkRealName,
trigger: 'blur'
}
],
colname: [
{required: true,validator: checkName, trigger: 'blur'}
],
},
tableHomeworkData: [
{
@@ -130,6 +165,19 @@ var Main = {
onSubmit() {
console.log('submit!');
}
},
mounted() {
this.$nextTick(() => {
var that = this;
axios.get('http://localhost:8080/cms/home/userinfo')
.then(function (response) {
console.log(response.data);
that.ruleForm2 = response.data;
})
.catch(function (error) {
console.log(error);
});
})
}
}
var Ctor = Vue.extend(Main)

View File

@@ -23,18 +23,18 @@
method="POST" name="register">
<el-form-item label="ID"
prop="coluserid">
<el-input :readonly="true"
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').coluserid}" name="coluserid" readonly></el-input>
<el-input :readonly="true" v-model="ruleForm2.coluserid"
name="coluserid" readonly></el-input>
</el-form-item>
<el-form-item label="用户名"
prop="colname">
<el-input
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colname}" name="colname" ref="name"></el-input>
<el-input v-model="ruleForm2.colname"
name="colname" ref="name"></el-input>
</el-form-item>
<el-form-item
label="密码" prop="colpassword">
<el-input type="password" placeholder="不改密码则留空"
v-model="ruleForm2.colpassword" auto-complete="off" name="colpassword"></el-input>
<el-input type="password" placeholder="不改密码则留空" v-model="ruleForm2.colpassword"
auto-complete="off" name="colpassword"></el-input>
</el-form-item>
<el-form-item label="确认密码" prop="checkPass">
<el-input placeholder="不改密码则留空"
@@ -43,19 +43,20 @@
</el-form-item>
<el-form-item prop="colemail" label="邮箱"
:rules="[
{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur,change' }
]">
<el-input th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colemail}" name="colemail" ref="email"></el-input>
<el-input v-model="ruleForm2.colemail" name="colemail" ref="email"></el-input>
</el-form-item>
<el-form-item label="学号"
prop="colstudentno">
<el-input
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colstudentno}" name="colstudentno" ref="studentno"></el-input>
<el-input v-model="ruleForm2.colstudentno"
name="colstudentno" ref="studentno"></el-input>
</el-form-item>
<el-form-item label="真实姓名"
prop="colrealname">
<el-input
th:value="${#httpServletRequest.getSession().getAttribute('USER_SESSION').colrealname}" name="colrealname" ref="realname"></el-input>
<el-input v-model="ruleForm2.colrealname"
name="colrealname" ref="realname"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary"