一、实验目的
1.掌握软件开发的基本流程
2.掌握常用的软件开发方式和工具。
二、实验内容
1.设计一个包含登录界面的计算器软件,该软件可以实现第一次作业中的功能,同时可以保存用户的历史计算记录(保存数据最好使用数据库)。
三、实验所用环境及工具
1.使用DW和IDEA编写
2.使用Visio绘制流程图
四、流程图
五、登录页面(使用DW)
1、login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="login-box">
<h2>登录</h2>
<form>
<div class="login-field">
<input type="text" name="" required="" />
<label>用户名</label>
</div>
<div class="login-field">
<input type="password" name="" required="" />
<label >密码</label>
</div>
<button type="submit">登录</button>
</form>
</div>
</body>
</html>
2、style.css
body{
margin: 0;
padding: 0;
font-family: sans-serif;
background: url("image/lzufeView.jpg");
background-size: cover;
background-position: center 0;
background-repeat: no-repeat;
background-attachment: fixed;
-webkit-background-size: cover;
-o-background-size: cover;
-moz-background-size: cover;
-ms-background-size: cover;
}
.login-box{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 400px;
padding:40px;
background: rgba(0,0,0,.8);
box-sizing: border-box;
box-shadow: 0 15px 25px rgba(0,0,0,.5);
border-radius: 10px;
}
.login-box h2{
margin: 0 0 30px;
padding: 0;
text-align: center;
color: #fff;
}
.login-box .login-field{
position: relative;
}
.login-box .login-field input{
width: 100%;
padding: 10px 0;
font-size: 16px;
color: #fff;
margin-bottom: 30px;
border: none;
border-bottom: 1px solid #fff;
outline: none;
background: transparent;
}
.login-box .login-field label{
position: absolute;
top: 0;
left: 0;
letter-spacing: 1px;
padding: 10px 0;
font-size: 16px;
color: #fff;
pointer-events: none;
transition: .5s;
}
.login-box .login-field input:focus ~ label,
.login-box .login-field input:valid ~ label{
top: -23px;
left: 0;
color: aqua;
font-size: 12px;
}
.login-box button{
background: transparent;
border: none;
outline: none;
color: #fff;
background: #03a9f4;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
}
3、实验结果
六、计算器界面
<!DOCTYPE html>
<html>
<head>
<title>计算器</title>
<style>
body {
background-image: url("image/lzufeView.jpg");
background-size: cover;
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
margin-top: 50px;
font-size: 30px;
}
.calculator {
background-color: #F5F5F5;
border-radius: 10px;
box-shadow: 0px 0px 10px #888888;
margin: 50px auto;
padding: 20px;
width: 300px;
}
.display {
background-color: #FFFFFF;
border: 1px solid #CCCCCC;
border-radius: 5px;
font-size: 24px;
height: 40px;
margin-bottom: 10px;
padding: 10px;
text-align: right;
width: 95%;
}
.button {
background-color: #CCCCCC;
border: none;
border-radius: 5px;
color: #000000;
cursor: pointer;
font-size: 24px;
height: 50px;
margin-bottom: 10px;
width: 23%;
}
.button:hover {
background-color: #DDDDDD;
}
.button:active {
box-shadow: none;
background-color: #AAAAAA;
}
.operator {
background-color: #A46D06;
color: #FFFFFF;
}
.equals {
background-color: #4CAF50;
color: #FFFFFF;
width: 48%;
}
</style>
</head>
<body>
<div class="calculator">
<div class="display" id="display"></div>
<button class="button" onclick="addToDisplay('7')">7</button>
<button class="button" onclick="addToDisplay('8')">8</button>
<button class="button" onclick="addToDisplay('9')">9</button>
<button class="button operator" onclick="addToDisplay('+')">+</button>
<button class="button" onclick="addToDisplay('4')">4</button>
<button class="button" onclick="addToDisplay('5')">5</button>
<button class="button" onclick="addToDisplay('6')">6</button>
<button class="button operator" onclick="addToDisplay('-')">-</button>
<button class="button" onclick="addToDisplay('1')">1</button>
<button class="button" onclick="addToDisplay('2')">2</button>
<button class="button" onclick="addToDisplay('3')">3</button>
<button class="button operator" onclick="addToDisplay('*')">×</button>
<button class="button" onclick="addToDisplay('0')">0</button>
<button class="button" onclick="addToDisplay('.')">.</button>
<button class="button operator" onclick="addToDisplay('/')">÷</button>
<button class="button" onclick="clearDisplay()">C</button>
<button class="button equals" onclick="calculate()">=</button>
</div>
<script>
function addToDisplay(value) {
document.getElementById("display").innerHTML += value;
}
function clearDisplay() {
document.getElementById("display").innerHTML = "";
}
function calculate() {
var expression = document.getElementById("display").innerHTML;
var result = eval(expression);
document.getElementById("display").innerHTML = result;
}
</script>
</body>
</html>
七、JDBC连接数据库原理
八、后端代码实现
UserController:
package com.carculator.controller;
import com.carculator.services.UserService;
import com.carculator.domain.ResultData;
import com.carculator.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @desc
* @date 2022年02月19日 2022/2/19
*/
@CrossOrigin
@RestController
public class UserController {
@Autowired
private UserService userService;
@Autowired
private User user;
@RequestMapping("login")
public ResultData userLogin(@RequestParam("userName") String userName,@RequestParam("passWord") String passWord){
System.out.println("前端输入的用户名是:"+userName);
System.out.println("前端输入的密码是:"+passWord);
int code = -1;
String msg = "";
User data = null;
User userByUserName = userService.findUserByUserName(userName);
if (userByUserName != null) {
System.out.println(userByUserName.toString());
if (userByUserName.getPassWord().equals(passWord)) {
code = 200;
msg = "登陆成功";
data = userByUserName;
} else {
code = 200;
msg = "密码错误";
}
} else {
code = 400;
msg = "用户名不存在";
}
ResultData response = new ResultData();
response.setCode(code);
response.setMsg(msg);
response.setData(data);
return response;
}
}
application.yml:
spring:
mvc:
contentnegotiation:
favor-parameter: true
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url=jdbc:mysql: //127.0.0.1:3306/java_test
username: root
password: root
CarculatorApplication:
package com.carculator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
@ServletComponentScan(basePackages = "com.electronicticket.weboriginalcomponent")
@SpringBootApplication
class CarculatorApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(CarculatorApplication.class, args);
}
}
User:
package com.carculator.domain;
import lombok.Data;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import javax.persistence.*;
@Component
@ConfigurationProperties(prefix = "user")
@Entity
@Table(name = "user")
@Data
@ToString
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "username")
private String userName;
@Column(name = "password")
private String passWord;
@Column(name = "realname")
private String realName;
@Column(name = "dress")
private String dress;
@Column(name = "telephone")
private String telphone;
@Column(name = "img")
private String img;
}
标签:box,color,background,org,import,login,实验报告 From: https://www.cnblogs.com/shierxixi/p/17873820.html