摘要::null);}}Stuid=请求。QueryString})播放UI。use(['layer','table','jquery','form'],function(){varlayer=playui.layer//播放层,table=playui.table//表,$=playui.jquery,form=playui.form;//执行表实例,table.render({elem:“#empTable”,totalRow:true,id:“bookReload”,height:620,page:true,url:“item/findOne?Stuid=”+Stuid//数据接口,title:“information table”,toolbar:“default”//启用工具栏。默认图标显示在此处。您可以自定义模板。有关详细信息,请参阅文档,cols:[//header{field:“id”,title:“number”,sort:true,180},{field:'createtime',title:'createtime',180},{field:'wd',titlet:'temperature',180,template:function{varspan=“”;if{return“”}if{returnspan+=''+d.wd+'';}返回。wd;}},{field:'student',title:'name',180,template:function{//varspan=“”;//if{//returnspan+=''+d.student.stuname+'';//}returnd.student。stuname;}},{field:'student',title:'gender',180,模板:函数{return d.studio.sex;}}]});});控制器创建一个会话对象,并将其转换为id所属类的对象。传递给前台的ID是通过会话对象的get方法获得的。publicStringfindTem{Studentstu=session.getAttribute;JsonDatajsonData=temService.findTem;returnJSON.toJSONString;}添加和修改publicStringsaveTem{Studentstu=session.getAttribute;temperature.setStudent;Stringformat=newSimpleDateFormat.format;temperation.setCreatetime;JsonDatajsonData=temService.saveTem;returnJSON.toJSONString;}详细信息查询@RequestMappingpublicStringfindOne{JsonDatajsonData=temService.findTem;returnJSON.toJSONString;}serviceImplpackagecom.hp.service。impl;importcom.hp.mapper。TemMaper;importcom.hp.pojo。温度importcom.hp.service。TemService;importcom.hp.util。JsonData;importorg.springframework.beans.factory.annotation。自动连线;进口。弹簧框架。立体造型。服务进口机构、弹簧框架、交易、通知。交易的导入java.util。列表;@Service@TransactionalpublicclassTemServiceImplimplementsTemService{@AutowiredprivateTeMappetemMapper;@OverridepublicJsonDatafindTem{Listtem=temMapper.findTem;returnJsonData.buildSuccess;}@OverridepublicJsonDatasaveTem{inti=0;if(temperature.getId()!
js页面
var stuid;
$(function () {
var request = {
QueryString : function(val) {
var uri = window.location.search;
var re = new RegExp("" +val+ "=([^&?]*)", "ig");
return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
}
}
stuid =request.QueryString("stuid")
})
layui.use(['layer', 'table', 'jquery', 'form'], function(){
var layer = layui.layer //弹层
,table = layui.table //表格
,$ = layui.jquery
,form = layui.form;
//执行一个 table 实例
table.render({
elem: '#empTable'
,totalRow: true
,id:'bookReload'
,height: 620
,page:true
,url: 'tem/findOne?stuid='+stuid //数据接口
,title: '信息表'
,toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
,cols: [[ //表头
{field: 'id', title: '编号', sort: true, 180}
,{field: 'createtime', title: '创建时间', 180}
,{field: 'wd', title: '温度', 180,templet: function(d) {
var span="";
if (d.wd==null){
return ""
}
if (d.wd>=37.3){
return span += '<span style="color: red">'+d.wd+'</span>';
}
return d.wd;
}}
,{field: 'student', title: '姓名', 180, templet: function(d){
// var span="";
// if (d.wd>=37.3){
// return span += '<span style="color: red">'+d.student.stuname+'</span>';
// }
return d.student.stuname;
}
}
,{field: 'student', title: '性别', 180 ,templet: function(d){
return d.student.sex;
}}
]]
});
});
Controller
创建 session对象 转换为 id所在类的对象,通过session对象的get方法获取到前台传来的id,
public String findTem(HttpSession session){
Student stu = (Student) session.getAttribute("stu");
JsonData jsonData = temService.findTem(stu.getStuid());
return JSON.toJSONString(jsonData);
}
添加和修改
public String saveTem(Temperature temperature,HttpSession session){
Student stu = (Student) session.getAttribute("stu");
temperature.setStudent(stu);
String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
temperature.setCreatetime(format);
JsonData jsonData = temService.saveTem(temperature);
return JSON.toJSONString(jsonData);
}
详情查询
@RequestMapping("/findOne")
public String findOne(int stuid){
JsonData jsonData = temService.findTem(stuid);
return JSON.toJSONString(jsonData);
}
serviceImpl
(老样子没啥可说了)
package com.hp.service.impl;
import com.hp.mapper.TemMapper;
import com.hp.pojo.Temperature;
import com.hp.service.TemService;
import com.hp.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class TemServiceImpl implements TemService {
@Autowired
private TemMapper temMapper;
@Override
public JsonData findTem(Integer stuid) {
List<Temperature> tem = temMapper.findTem(stuid);
return JsonData.buildSuccess(tem);
}
@Override
public JsonData saveTem(Temperature temperature) {
int i=0;
if (temperature.getId()!=null){
i=temMapper.editTem(temperature);
}else {
i=temMapper.addTem(temperature);
}
if (i>0){
return JsonData.buildSuccess("保存或修改成功");
}
return JsonData.buildError("保存或修改失败");
}
@Override
public JsonData delTem(int id) {
int i = temMapper.delTem(id);
if (i>0){
return JsonData.buildSuccess("del success");
}
return JsonData.buildError("del error");
}
}
mapper.xml
<?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="com.hp.mapper.TemMapper">
<resultMap type="com.hp.pojo.Temperature">
<id property="id" column="id"></id>
<result property="createtime" column="createtime"/>
<result property="wd" column="wd"/>
<association property="student" column="stuid" javaType="com.hp.pojo.Student">
<id property="stuid" column="stuid"/>
<result property="username" column="username"/>
<result property="pwd" column="pwd"/>
<result property="stuname" column="stuname"/>
<result property="sex" column="sex"/>
<result property="status" column="status"/>
</association>
</resultMap>
<select resultMap="Tem">
SELECT t.*, s.username,s.pwd,s.stuname,s.sex FROM temperature t, student s WHERE s.stuid = t.stuid and s.stuid=#{stuid}
</select>
<insert id="addTem">
insert into temperature (createtime,wd,stuid) VALUES(#{createtime},#{wd},#{student.stuid})
</insert>
<update id="editTem">
update temperature set createtime=#{createtime},wd=#{wd},stuid=#{student.stuid} where id=#{id};
</update>
<delete id="delTem">
delete from temperature where id=#{id}
</delete>
</mapper>