思途实训-day02

语录

挤在人群中,面带微笑。但无论这微笑有多么甜美,都难以掩饰微笑背后的落寞与无奈。
因为根本上,人和人的灵魂是无法相通的。在无法相通的隔阂与孤独中,我只能挤进人群,面带微笑。

上午

杜老师带我们写出了剩下的两个模块,分别是controller和serivce

  1. Departmentcontroller.java

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
     
    package com.situ.company.department.controller;

    import java.util.List;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

    import com.situ.company.department.model.DepartmentModel;
    import com.situ.company.department.service.DepartmentService;


    @RestController
    @RequestMapping("department")
    public class DepartmentController
    {
    @Autowired
    private DepartmentService service;

    @RequestMapping("insert")
    public int insert(DepartmentModel model)
    {

    return service.insert(model);
    }

    @RequestMapping("delect")
    public int delect(DepartmentModel model)
    {
    return service.delect(model);
    }

    @RequestMapping("updata")
    public int updata(DepartmentModel model)
    {
    return service.updata(model);
    }

    @RequestMapping("selectmodel")
    public DepartmentModel selectmodel(DepartmentModel model)
    {
    return service.selectModel(model);
    }

    @RequestMapping("selectList")
    public List<DepartmentModel> select(DepartmentModel model)
    {
    return service.selectList(model);
    }
    }
  1. DepartmentSerivce.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    package com.situ.company.department.service;

    import java.util.List;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import com.situ.company.department.mapper.DepartmentMapper;
    import com.situ.company.department.model.DepartmentModel;


    @Service
    public class DepartmentService
    {
    @Autowired
    private DepartmentMapper mapper;

    public int insert(DepartmentModel model)
    {
    DepartmentModel mdb = selectModel(model);
    if(mdb == null)
    {
    return mapper.insert(model);
    }
    else
    {
    return -1;
    }
    }


    public int delect(DepartmentModel model)
    {
    return mapper.Delete(model);
    }

    public int updata(DepartmentModel model)
    {
    return mapper.updata(model);
    }

    public DepartmentModel selectModel(DepartmentModel model)
    {
    return mapper.selectModel(model);
    }

    public List<DepartmentModel> selectList(DepartmentModel model)
    {
    String name = model.getName();
    if(name == null)//此处的null必须变成“”,否则下面的setName拼接成的为%null% 查询的是name中含有name的字符
    {
    name = "";
    }
    model.setName('%' + name + '%');
    return mapper.selectList(model);
    }
    }
  • Model模块是建立私有化的数据类型,相当于建立数据库中的对应数据。

  • Mapper模块在Model基础上进行数据库(sql)语句的编辑(增删改查)

  • Service模块在Mapper基础上进行一些逻辑化的操作。例如:id(主键)和code(非主键),但我想让code的值是唯一的,这时候需要用到Service模块的的操作,代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    public int insert(DepartmentModel model) 
    {
    DepartmentModel mdb = selectModel(model);
    if(mdb == null)
    {
    return mapper.insert(model);
    }
    else
    {
    return -1;
    }
    }
  • 最后是Controller模块,这个模块对应的是网页端,给网页服务的。

1
@RequestMapping("insert")

这个地方的insert和网页的请求一样,不能写错。
3.

下午

老师讲解使用网页端来进行数据库的增删改查

  • 刚开始,老师直接使用在网址中输入的命令
1
http://127.0.0.1:8080/company/department/insert?code=1&name=hls&tel=17852031547
  • 然后直接转到网页端,新建一个html文件,文件代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/company/base/js/jquery-3.3.1.min.js"></script>
<style>
body {
background-image:url('9.jpg');
height: 100%;
width: 100%;
background-size: cover;
position: absolute;
overflow: hidden;
}
#login{
width:400px;
height:280px;
position:absolute;
left: 50%;
top: 40%;
margin-left:-200px;
margin-top:-140px;
border:1px;
align:center;
}
#form{
width:300px;
height:160px;
position:relative;
left:50%;
top:40%;
margin-left:-150px;
margin-top:-80px;
}
#img{
width:300px;
height:160px;
position:relative;
left:55%;
top:29.4%;
margin-left:-150px;
margin-top:-80px;
}
#bu1{
background-color: black;
width:50px;
height:40px;
}
#bu2{
background-color: black;
width:50px;
height:40px;
}
#bu3{
background-color: black;
width:100px;
height:40px;
}
</style>
</head>
<body>
<div id = "img">
<img src="8.jpg" width="165" height="60" />
</div>
<div id = "login">
<div id = "form">
<form>
<h3 align="center" style="color:green" >部门注册系统</h3>
*&nbsp;&nbsp;账&nbsp;&nbsp;号: <input type='text' name = 'code'><br><br>
*&nbsp;&nbsp;名&nbsp;&nbsp;称: <input type='text' name = 'name'><br><br>
*&nbsp;&nbsp;电&nbsp;&nbsp;话: <input type='text' name = 'tel'><br>
<br>
&nbsp;&nbsp;<input id = "bu1" style = "color: white" type="button" value="注册" onclick="test()">
&nbsp;&nbsp;&nbsp;&nbsp;<input id = "bu2" style = "color: white" type="button" value="重置" onclick="test1()">
&nbsp;&nbsp;&nbsp;&nbsp;<input id = "bu3" style = "color: white" type="button" value="成员注册页面" onclick="test2()">
</form>
</div>
</div>
</body>
<script type="text/javascript">
function test1()
{
window.location.href="http://127.0.0.1:8080/company/web/department.html";
}
function test()
{
var code = $("input[name='code']").val();
var name = $("input[name='name']").val();
var tel = $("input[name='tel']").val();
//htpp://127.0.0.1:8080/company/department/insert?code=a1&name=a2&pass=a3
$.ajax({
url:'/company/department/insert',
//data:'code='+code+'&name='+name+'&pass='+pass, //从网页端到java发送的请求参数
data:{code:code,name:name,tel:tel},
dataType:'json', //返回的数据类型 java返回至网页端
type:'post', //请求的方式
success:function(d)
{
console.log(d)
}
})
}
function test2(){
window.open('http://127.0.0.1:8080/company/web/Employee.html');
}
</script>
</html>

这样就可以实施网页端的操作。

晚上

巩固网页端的知识,自己查询了HTML和CSS的一些操作,做出来了一个小小的界面
部门注册
感觉杜老师真好,有问必答,太敬业了。
明天差不多要开始真正的做界面和逻辑化了,溜了,溜了!

0%
-->