栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

学习记录六

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

学习记录六

一、力扣打卡

今天做的是将数字转换为罗马数字,其实前两天做了将罗马数字转换为数字,罗马数字转换为数字的规则是由于罗马数字中间的规律就是,只要是正确的罗马数字,就一定有,当左边的小于右边的就减去,大于右边的就加上,使用一些小的循环就可以得到结果了!

对于罗马数字转为数字其实要简单一点,然后对于数字转换为罗马数字,其实我们只需要将特殊情况列举出来,然后使用枚举法很容易求解,这里使用的是另外一种方式

根据规则

我们可以知道存在以下情况

根据罗马数字的唯一表示法,为了表示一个给定的整数 textit{num}num,我们寻找不超过 num 的最大符号值,将num 减去该符号值,然后继续寻找不超过num 的最大符号值,将该符号拼接在上一个找到的符号之后,循环直至 num 为 00。最后得到的字符串即为num 的罗马数字表示。

代码如下所示

class Solution {
    int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
    String[] symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

    public String intToRoman(int num) {
        StringBuffer roman = new StringBuffer();
        for (int i = 0; i < values.length; ++i) {
            int value = values[i];
            String symbol = symbols[i];
            while (num >= value) {
                num -= value;
                roman.append(symbol);
            }
            if (num == 0) {
                break;
            }
        }
        return roman.toString();
    }
}

二、SpinrgJdbc Template的基本使用

1.JdbcTemplate概述

是Spring框架中提供的一个对象,是对原始繁琐的jdbc API对象的简单封装。spring为我们提供了很多的操作模板类。比如:操作关系数据库的JdbcTemplate和HibernateTemplate

2. JdbcTemplate的开发步骤

①导入Spring-jdbc和spring-tx的坐标

②创建数据库表和实体

③创建Jdbc Template对象

④执行数据库操作

代码如下所示:

pom.xml


        
            mysql
            mysql-connector-java
            5.1.45
        
        
            com.mchange
            c3p0
            0.9.5.2
        

        
            com.alibaba
            druid
            1.1.6
        

        
            junit
            junit
            4.12
        
        
            junit
            junit
            RELEASE
            compile
        

        
            org.springframework
            spring-context
            4.3.17.RELEASE
        

        
            org.springframework
            spring-test
            4.3.17.RELEASE
        

        
            org.springframework
            spring-context
            4.3.17.RELEASE
            compile
        
        
            org.springframework
            spring-context
            4.3.17.RELEASE
            compile
        
        
            org.springframework
            spring-jdbc
            4.3.17.RELEASE
        
        
            org.springframework
            spring-tx
            4.3.17.RELEASE
        
    

JdbcTemplateTest.java

public class JdbcTeplateTest {
    @Test
    //测试JdbcTemplate开发步骤
    public void test1() throws PropertyVetoException {

        //创建数据源对象
        ComboPooledDataSource dataSource=new ComboPooledDataSource();
        dataSource.setDriverClass("com.mysql.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8");
        dataSource.setUser("root");
        dataSource.setPassword("546871893wxy.");

        JdbcTemplate jdbcTemplate=new JdbcTemplate();
        //设置数据源对象 知道数据库在哪里
        jdbcTemplate.setDataSource(dataSource);

        //执行操作
        int tom = jdbcTemplate.update("insert into account values(?,?) ", "tom", 5000);
        System.out.println(tom);

    }
}

然后在执行的时候出现了错误,可以参考本人这篇博客

解决错误:java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is unrecognized or represents_young_man2的博客-CSDN博客

还有一些内容记得看自己的代码【提醒自己的,嘿嘿嘿】

 最后放上今天的美文

Gratitude is not only the greatest of virtues, but the parent of all others.

感恩不仅是最好的美德,还是其他美德之母

最后就是图片啦!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1004425.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号