美文网首页
1. Java 入门

1. Java 入门

作者: dolenlen | 来源:发表于2017-05-18 23:20 被阅读0次

第一步 准备

最新版Java

  • Java8

开发工具IDE

数据库

  • 推荐Mysql
  • 也可以Oracle

数据库工具

  • Mysql推荐Sqlyog
  • Oracle推荐Plsql Developer

开发框架

构建工具

  • Maven(本人熟悉点),本地要安装,方便命令行执行
  • Gradle(现在很火爆,Android都是基于此)

第二步 HelloWorld

hw-maven

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

hw-java

package hello;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

hw-测试

  • 运行上面Java类中的main
  • 浏览器输入,一般默认是8080端口,若不对,可查询运行的日志,上面有
  • localhost:8080

第三步 连接数据库

db-maven

  • 需启动MySQL
  • 需引入MySQL的JDBC驱动包
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

配置application.properties

spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://localhost:3306/hello?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=

db-java

第四步 编写简单页面

相关文章

网友评论

      本文标题:1. Java 入门

      本文链接:https://www.haomeiwen.com/subject/qoyexxtx.html