0
点赞
收藏
分享

微信扫一扫

Hive主要介绍

at小涛 2024-05-02 阅读 52

目录

POJO(作为实体): 添加注释@Entity @Id

 DAO(作为存储库):使用Spring Boot时,不需要具体的DAO实现或JdbcUtils

COMMON(应用配置):JdbcUtils 与 JdbcTemplate bean(放入config包)

exception(自定义异常)

sercurity

servlet :换为controller


操作                         servlet                          springboot
改包名(可改可不改)commonconfig
添加注解pojopojo
添加注解serviceservice
添加注解exceptionexception
替换servletcontroller
添加注解daodao
添加注解sercuritysercurity

POJO(作为实体): 添加注释@Entity @Id

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class EasUser {
    @Id
    private Long id;
    private String username;
    private String password; // 考虑使用散列存储密码以提高安全性

    // getters 和 setters
}

 DAO(作为存储库):使用Spring Boot时,不需要具体的DAO实现JdbcUtils

COMMON(应用配置):JdbcUtils 与 JdbcTemplate bean(放入config包)

JpaRepository处理了大多数常见的数据访问模式,如果需要针对JDBC的特定配置或工具,可以在配置中配置一个JdbcTemplate bean(一般不需要,可以不用增加)

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

@Configuration
public class JdbcConfig {

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/yourDatabase");
        dataSource.setUsername("username");
        dataSource.setPassword("password");
        return dataSource;
    }

    @Bean
    public JdbcTemplate jdbcTemplate(DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}

exception(自定义异常)

sercurity

servlet :换为controller

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/login")
    public ResponseEntity<?> loginUser(@RequestParam String username, @RequestParam String password) {
        EasUser user = userService.loginUser(username, password);
        if (user != null) {
            return ResponseEntity.ok(user);
        } else {
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
        }
    }
}

service:加密

举报

相关推荐

Hive SQL主要开窗函数用法介绍

Hive介绍

Jmeter主要组件介绍

Hive 安装介绍

0 条评论