第一次创建springboot框架项目

第一次创建springboot框架项目

  • 1.1_创建步骤
  • 2.1_启动时遇到的问题
    • 2.2_启动响应网页测试
    • 2.3_连接数据库尝试

1.1_创建步骤

(1)创建spring项目
在这里插入图片描述

(2)
在这里插入图片描述

(3)
在这里插入图片描述

加入引擎
在这里插入图片描述

在这里插入图片描述
下一步即可

2.1_启动时遇到的问题

(1)刚开始没有启动图标,等一会就好了
在这里插入图片描述
(2)后来启动失败并报错ERROR 3704 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :

因为默认端口是8080,若已被占用需要更改默认端口号

在这里插入图片描述
修改方法:修改application.properties文件,在文件中添加:

server.port=8081
server.context-path=/demo

在这里插入图片描述

启动成功:
在这里插入图片描述

(3)接下来访问http://localhost:8081/ 成功,但是后来过了一天又不行了发现是目录的问题
应该访问http://localhost:8081/demo
在这里插入图片描述

2.2_启动响应网页测试

package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController//响应服务器,与@RequestMapping配合使用(“@RestController配合@RequestMapping”与“@Controller配合@ResponseBody再配合@RequestMapping”效果一样)
@SpringBootApplication//声明该类是一个springboot引导类,
public class DemoApplication {public static void main(String[] args) {//run方法表示运行springboot的引导类SpringApplication.run(DemoApplication.class, args);}@RequestMappingpublic String hello() {return "hello spring boot!";}
}

在浏览器搜索:“http://localhost:8081/”

在这里插入图片描述

2.3_连接数据库尝试

package com.example.demo;
import java.sql.*;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController//响应服务器,与@RequestMapping配合使用(“@RestController配合@RequestMapping”与“@Controller配合@ResponseBody再配合@RequestMapping”效果一样)
@SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}@RequestMappingpublic String hello()throws Exception {SqlOperation.main();ResultSet resultSet = SqlOperation.statement.executeQuery("select * from Score");String s;resultSet.next();s = resultSet.getString("name");return s;}
}

class SqlOperation {public static Connection connection = null;//定义连接数据库的对象(桥梁)public static String url = "jdbc:sqlserver://localhost:1433;DatabaseName=Studentinfo";public static Statement statement = null;//定义静态操作对象public static PreparedStatement preparedStatement = null;//定义动态操作对象public static void main() {try{//第一步加载驱动Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");System.out.println("加载驱动成功!");//第二步建立连接connection = DriverManager.getConnection(url,"sa","shejiashuai");System.out.println("连接数据库成功!");//第三步建立操作对象statement = connection.createStatement();}catch (Exception e){e.printStackTrace();System.out.println("连接数据库失败!");}}public static void close(){//关闭连接try{statement.close();connection.close();}catch (Exception e){e.printStackTrace();}}
}

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545374.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

JAVA学习--集合的遍历

1 Test2 public void testFor3(){3 String[] str new String[]{"AA","BB","DD"};4 for(String s : str){5 s "MM";//此处的s是新定义的局部变量,其值的修改不会对str本身造成影响。6 …

技能学习指南

经过前面文章的学习,我相信一定有一半的人看懂了,而另一半人一定是似懂非懂或者是完全不懂,如果你属于前者,那恭喜你,但如果没看懂,也没关系,本文来给你具体的解决方案。 我们来仔细回忆两件事,第一件是大学考级学的那些英语,我每个单词每个语句当时都背的滚瓜烂熟,…

转载:VB监视进程

从百度知道看的,VB监视进程: 让VB程序监视进程中的名称“Windows 任务管理器”,和“AAA”两个进程的进程名,而且进行操作:如果“Windows 任务管理器”被关闭时则自动关闭“进程某某”程序!可以用一个 Timer 定时执行下…

Java字符类isLowerCase()方法与示例

字符类isLowerCase()方法 (Character class isLowerCase() method) isLowerCase() method is available in java.lang package. isLowerCase()方法在java.lang包中可用。 isLowerCase() method is used to check whether the given char value is lowercase or not. isLowerCas…

JPA使用

JPA使用1.1_persistence使用问题1.1_persistence使用问题 import javax.persistence.*; 需要在pom文件加入依赖&#xff1a; <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId>&…

附录:更多字典操作命令

插入一个或多个元素 语法:hmset key field value [field value …] 示例: 127.0.0.1:6379> hmset myhash k1 val1 k2 val2 OK 127.0.0.1:6379> hmget myhash k1 k2 1) "val1" 2) "val2"查询一个或多个元素 语法:hmget key field [field …] 示…

Movie

悬疑片&#xff1a; 嫌疑人X的献身转载于:https://www.cnblogs.com/lnlvinso/p/4264804.html

hibernate中对象的3种状态----瞬时态、持久态、脱管态

转载&#xff1a; http://www.blogjava.net/amigoxie/archive/2007/02/11/99342.htmlHibernate的对象有3种状态&#xff0c;分别为&#xff1a;瞬时态(Transient)、 持久态(Persistent)、脱管态(Detached)。处于持久态的对象也称为PO(Persistence Object)&#xff0c;瞬时对象和…

java 根据类名示例化类_Java LocalDateTime类| ofInstant()方法与示例

java 根据类名示例化类LocalDateTime类的Instant()方法 (LocalDateTime Class ofInstant() method) ofInstant() method is available in java.time package. ofInstant()方法在java.time包中可用。 ofInstant() method is used to create an instance of LocalDateTime from t…

附录:更多字符串操作命令

键值对过期操作 a.添加键值对并设置过期时间 语法:set key value [expiration EX seconds|PX milliseconds] [NX|XX] 示例: 127.0.0.1:6379> set k1 val1 ex 1000 OK设置键值对 k1=val1,过期时间为 1000 秒。 查询键的过期时间可以使用 ttl key,如下代码所示: 127.…

ACM - 第6章 数据结构基础(2)

6.4.2 走迷宫 利用bfs寻找最短路。通过对u/m得到x&#xff0c;u%m得到y。u x * m y 将方向保存在dx[], dy[]中。 cint q[maxn*maxn]; void bfs(int x, int y) {int front 0, rear 0, d, u;u x*m y;vis[x][y] 1; fa[x][y] u; dist[x][y] 0;q[rear] u;while(front <…

springboot工程的热部署

springboot工程的热部署&#xff08;1&#xff09;第一步配置pom.xml&#xff08;2&#xff09;第二步更改IDEA设置什么是热部署配置呢&#xff1f; 我们在开发中反复修改类、页面等资源&#xff0c;每次修改后都是需要重新启动才生效&#xff0c;这样每次启动都很麻烦&#xf…

java 简单的加法 递归 从A加到B

public class Main {// 设置保存和的变量static int sum 0;public static void main(String[] args) {int begin 1, end 10;// 调用方法一 sum 0;sum add(begin, end);System.out.println(">>> 从 " begin " 开始加到 " end " 的结…

Java LocalDateTime类| 带示例的compareTo()方法

LocalDateTime类compareTo()方法 (LocalDateTime Class compareTo() method) compareTo() method is available in java.time package. compareTo()方法在java.time包中可用。 compareTo() method is used to compare this date-time object to the given date-time object. co…

附录:更多集合操作命令

移除并返回集合中的一个随机元素 语法:spop key [count] 示例: 127.0.0.1:6379> smembers myset 1) "v1" 2) "v2" 127.0.0.1:6379> spop myset 1 1) "v2" 127.0.0.1:6379> smembers myset 1) "v1"随机返回集合中指定数量…

第一二章(PTA复习)

第一二章因为3默认是整形&#xff0c;整形长度大于short型&#xff0c;如果让short型 short型 int型&#xff0c;可能会溢出&#xff0c;所以编译报错 例如&#xff1a; 答案&#xff1a;D switch 语句中的变量类型可以是&#xff1a; byte、short、int 或者 char。从 Java …

附录:更多列表操作命令

在某值之前/之后添加某个元素 语法&#xff1a;linsert key before|after pivot value 示例&#xff1a; 127.0.0.1:6379> linsert list3 before b A (integer) 4 127.0.0.1:6379> lrange list3 0 -1 "a" "A" "b" "c"根据下标…

code craft_Craft.io调度中使用的重要术语

code craft1) Arrival Time (AT) 1)到达时间(AT) The time when the process arrives into the running state is called as the Arrival time of the process. In simple words, the time at which any process enter the CPU is known as the arrival time. 流程到达运行状态…

英语笔记:写作:Free admissionsto museums

Free admissionsto museums 免费开放博物馆 Recently, more and more museums areopen to the public free of charge so that they can attract more visitors. However,it has also brought some unexpected problems. Should we carry on the practice? People’sviews va…

ExtJS和AngularJS比较

原文地址&#xff1a;http://www.techferry.com/articles/ExtJS-vs-AngularJS.html ExtJS和AngularJS比较.pdf转载于:https://www.cnblogs.com/animal/p/4267109.html