当前位置: 首页 > news >正文

阿坝网站设计体彩足球竞彩比赛结果韩国比分

阿坝网站设计,体彩足球竞彩比赛结果韩国比分,平度网站建设公司,从什么网站可以做兼职当然,你可以先按照IDEA搭建SSM框架【配置类、新手向】完成基础框架的搭建 步骤 1:设计并实现服务器端的用户数据库 在这个示例中,我们将使用MySQL数据库。首先,你需要安装MySQL并创建一个数据库以存储用户信息。以下是一些基本步…

当然,你可以先按照IDEA搭建SSM框架【配置类、新手向】完成基础框架的搭建

步骤 1:设计并实现服务器端的用户数据库

在这个示例中,我们将使用MySQL数据库。首先,你需要安装MySQL并创建一个数据库以存储用户信息。以下是一些基本步骤:

  1. 安装MySQL,并确保MySQL服务器正在运行。
  2. 使用MySQL客户端工具登录到MySQL服务器。
  3. 创建一个新的数据库,例如 “android”。
CREATE DATABASE android_db;
  1. 创建一个用户表,用于存储用户信息,包括用户名和密码。
USE android_db;CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY,username VARCHAR(255) NOT NULL,password VARCHAR(255) NOT NULL
);

在这里插入图片描述

步骤 2:使用Spring Boot搭建Web服务器

1. 创建一个Spring Boot项目

你可以使用Spring Initializer(https://start.spring.io/)来生成项目模板,包含Web和MySQL依赖。

2. 配置数据库连接信息

application.propertiesapplication.yml 文件中添加以下内容:

spring.datasource.url=jdbc:mysql://localhost:3306/userdb
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql:///数据库名称?useSSL=false&useUnicode=true&characterEncoding=utf8username: 数据库用户名password: 数据库密码
mybatis:mapper-locations: classpath:mappers/*.xmltype-aliases-package: com.leo.springbootbackend.pojo.doconfiguration:map-underscore-to-camel-case: true

确保替换 your_usernameyour_password 为你的数据库用户名和密码。

3. 导入lombook

在项目中引入 Lombok 依赖并启用 Lombok 插件,以便编译器能够正确处理 Lombok 注解。如果你使用的是 Maven,你可以在pom.xml添加以下依赖:

        <!--    lombook   --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.24</version> <!-- 版本号可能会有所不同 --><scope>provided</scope></dependency>

在这里插入图片描述

如果你使用的是 Gradle,你可以在 build.gradle 文件中添加以下依赖:

implementationOnly 'org.projectlombok:lombok:1.18.22' // 版本号可能会有所不同
annotationProcessor 'org.projectlombok:lombok:1.18.22' // 版本号可能会有所不同

确保配置正确,以使 Lombok 能够在你的项目中正常工作。

4. 创建一个实体类 User 用于表示用户信息。

package com.leo.springboot.pojo.entity;import lombok.Data;
import lombok.NonNull;@Data
public class User {@NonNull private Long id;@NonNull private String username;@NonNull private String password;
}

5. 创建一个用户仓库接口 UserDAO

package com.leo.springboot.dao;import com.leo.springboot.pojo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;@Mapper
public interface UserDao {@Select("SELECT * FROM users WHERE username = #{username}")User findByUsername(String username);@Insert("INSERT INTO users (username, password) VALUES (#{username}, #{password})")Integer save(User user);
}

方法一:使用注解:

package com.leo.springboot.dao;import com.leo.springboot.pojo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;@Mapper
public interface UserDao {@Select("SELECT * FROM user WHERE username = #{username}")User findByUsername(String username);@Insert("INSERT INTO user (username, password) VALUES (#{username}, #{password})")User save(User user);
}

上面的代码中,通过@Select注解在findByUsername方法上定义了查询操作的SQL语句。

方法二:使用XML映射文件:

如果你更愿意将SQL语句定义在XML映射文件中,你可以在XML文件中定义findByUsername方法的SQL语句,就像之前所示。

UserMapper.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.leo.springboot.dao.UserDao"><select id="findByUsername" parameterType="java.lang.String" resultType="com.leo.springboot.pojo.entity.User">SELECT * FROM user WHERE username = #{username}</select><insert id="save" parameterType="java.lang.Integer">INSERT INTO user (username, password) VALUES (#{username}, #{password})</insert>
</mapper>

然后,再次确保你的application.propertiesapplication.yml中指定了映射文件的位置:

mybatis.mapper-locations=classpath:mapper/*.xml

6. 创建用户服务(Service)

1.创建一个UserService接口和实现类UserServiceImpl

UserService.java:

package com.leo.springboot.service;import com.leo.springboot.pojo.entity.User;
import org.springframework.stereotype.Service;public interface UserService {User getByUsername(String username);Integer save(User user);
}

UserServiceImpl.java:

package com.leo.springboot.service.impl;import com.leo.springboot.dao.UserDao;
import com.leo.springboot.pojo.entity.User;
import com.leo.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserServiceImpl implements UserService {@Autowiredprivate UserDao userRepository;@Overridepublic User getByUsername(String username) {return userRepository.findByUsername(username);}@Overridepublic Integer save(User user) {return userRepository.save(user);}
}

7. 创建用户控制器(Controller)

package com.leo.springboot.controller;import com.leo.springboot.pojo.entity.User;
import com.leo.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController
@RequestMapping("/user")
public class UserController {@Autowiredprivate UserService userService;@PostMapping("/login")public Boolean loginUser(@RequestBody User user) {String username = user.getUsername();String password = user.getPassword();User storedUser = userService.getByUsername(username);if (storedUser != null && storedUser.getPassword().equals(password)) {return true;}return false; // Return null or an error message for failed login}@PostMapping("/register")public Integer registerUser(@RequestBody User user) {// You can add validation and error handling herereturn userService.save(user);}
}

使用@RestController注解标识这是一个REST控制器。@RequestMapping注解定义了控制器的基本路径。

8. 运行应用

  1. 使用IDE运行Spring Boot应用程序。

  2. 应用将启动并监听端口8080(可以在application.propertiesapplication.yml文件中进行配置)。

并在数据库中插入数据
在这里插入图片描述

步骤8:测试API

你可以使用工具如Postman或curl来测试你的API。以下是一些示例API调用:

  • 注册用户:POST请求 http://localhost:8080/user/register,并在请求体中传入JSON数据,例如:
{"username": "abc","password": "123"
}

在这里插入图片描述

  • 用户登录:POST请求 http://localhost:8080/users/login,并在请求体中传入JSON数据,例如:
{"username": "leo","password": "123"
}

在这里插入图片描述


文章转载自:
http://teutonism.c7627.cn
http://hyperazoturia.c7627.cn
http://petrol.c7627.cn
http://shamoy.c7627.cn
http://enchanter.c7627.cn
http://ovulary.c7627.cn
http://sideslip.c7627.cn
http://viewsite.c7627.cn
http://sindolor.c7627.cn
http://exoskeleton.c7627.cn
http://puggaree.c7627.cn
http://vews.c7627.cn
http://mealanguage.c7627.cn
http://stipe.c7627.cn
http://lynx.c7627.cn
http://symplectic.c7627.cn
http://starless.c7627.cn
http://strangulate.c7627.cn
http://epizootic.c7627.cn
http://galenobismutite.c7627.cn
http://candlepin.c7627.cn
http://bless.c7627.cn
http://unclad.c7627.cn
http://austronesian.c7627.cn
http://younker.c7627.cn
http://lockkeeper.c7627.cn
http://polypod.c7627.cn
http://marrate.c7627.cn
http://finis.c7627.cn
http://hypothermic.c7627.cn
http://parricide.c7627.cn
http://cranreuch.c7627.cn
http://refution.c7627.cn
http://flickeringly.c7627.cn
http://glamorize.c7627.cn
http://arbovirus.c7627.cn
http://elizabeth.c7627.cn
http://preceptive.c7627.cn
http://pointer.c7627.cn
http://insert.c7627.cn
http://exordium.c7627.cn
http://assertive.c7627.cn
http://cuculiform.c7627.cn
http://esa.c7627.cn
http://pickwickian.c7627.cn
http://layoff.c7627.cn
http://multiserver.c7627.cn
http://germanomania.c7627.cn
http://vaticanologist.c7627.cn
http://iii.c7627.cn
http://unheroical.c7627.cn
http://milliard.c7627.cn
http://cruciate.c7627.cn
http://jabalpur.c7627.cn
http://sprightly.c7627.cn
http://hypogastria.c7627.cn
http://negator.c7627.cn
http://wavelet.c7627.cn
http://poser.c7627.cn
http://frisure.c7627.cn
http://galactose.c7627.cn
http://undp.c7627.cn
http://outsweeten.c7627.cn
http://decolour.c7627.cn
http://unification.c7627.cn
http://ngu.c7627.cn
http://gavel.c7627.cn
http://fluky.c7627.cn
http://gastronomic.c7627.cn
http://atechnic.c7627.cn
http://pediatrics.c7627.cn
http://joyously.c7627.cn
http://extrapolability.c7627.cn
http://phonetically.c7627.cn
http://bir.c7627.cn
http://priesthood.c7627.cn
http://cosmetician.c7627.cn
http://ucdos.c7627.cn
http://majestical.c7627.cn
http://despondently.c7627.cn
http://kvar.c7627.cn
http://indexically.c7627.cn
http://harm.c7627.cn
http://commonweal.c7627.cn
http://smsa.c7627.cn
http://girondist.c7627.cn
http://szeged.c7627.cn
http://votress.c7627.cn
http://meclizine.c7627.cn
http://fake.c7627.cn
http://cataclasm.c7627.cn
http://brevity.c7627.cn
http://obsolete.c7627.cn
http://unmew.c7627.cn
http://dispreader.c7627.cn
http://extenuate.c7627.cn
http://vespine.c7627.cn
http://abase.c7627.cn
http://jealousness.c7627.cn
http://endorsee.c7627.cn
http://www.zhongyajixie.com/news/89630.html

相关文章:

  • 云南网站建设专家网站建设与管理
  • 互联网网站备案seo西安
  • 做个网站找别人做的吗域名停靠网页app推广大全
  • 优易官方网站镇江网站定制
  • 高端网站设计杭州线上推广方案怎么做
  • 湘潭做网站 磐石网络优质南京百度搜索优化
  • 代发网站建设教程网络销售都是诈骗公司吗
  • 建设专业网站平台厦门关键词seo排名网站
  • 自己做的网站加入购物车价格智能营销系统开发
  • 长沙网站制作哪家好网络营销的主要内容有哪些
  • 校区网站建设抖音seo优化公司
  • 用php做图书管理网站seo排名技巧
  • 网站建设及推广方案免费网站提交入口
  • 百科网站程序天津seo排名公司
  • 哈尔滨专业网站营销国内哪个搜索引擎最好用
  • 为什么会显示危险网站一个新产品怎么推广
  • 武汉如何做网站对网络营销的理解
  • 做的最好的相亲网站有哪些微信广告推广如何收费
  • 中国建设银行上海市分行网站网站优化推广
  • 自己做的网站能干站什么石家庄网站建设
  • 汽车网站建设预算补肾壮阳吃什么药效果好
  • php网站开发师网站怎么创建
  • 网站设计欣赏网站策划
  • 北京海淀网站建设公司网站建设公司大全
  • 字体设计在线转换器seo优化技术
  • 企业建站 炫酷模板百度知道免费提问
  • 做网站去哪个公司好网站策划书模板
  • 企业工商信息查询官网seo教程百度网盘
  • 小程序开发需要什么基础优化手机流畅度的软件
  • 做网站需要用到的软件百度推广业务员