Skip to content

Commit 47bf09f

Browse files
committed
升级版本及更新文档
1 parent 23e3247 commit 47bf09f

12 files changed

Lines changed: 347 additions & 284 deletions

File tree

Spring-Boot-JdbcTemplate/.mvn/wrapper/MavenWrapperDownloader.java

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
11
/*
2-
Licensed to the Apache Software Foundation (ASF) under one
3-
or more contributor license agreements. See the NOTICE file
4-
distributed with this work for additional information
5-
regarding copyright ownership. The ASF licenses this file
6-
to you under the Apache License, Version 2.0 (the
7-
"License"); you may not use this file except in compliance
8-
with the License. You may obtain a copy of the License at
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
916

10-
https://www.apache.org/licenses/LICENSE-2.0
11-
12-
Unless required by applicable law or agreed to in writing,
13-
software distributed under the License is distributed on an
14-
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
KIND, either express or implied. See the License for the
16-
specific language governing permissions and limitations
17-
under the License.
18-
*/
19-
20-
import java.io.File;
21-
import java.io.FileInputStream;
22-
import java.io.FileOutputStream;
23-
import java.io.IOException;
24-
import java.net.URL;
25-
import java.nio.channels.Channels;
26-
import java.nio.channels.ReadableByteChannel;
17+
import java.net.*;
18+
import java.io.*;
19+
import java.nio.channels.*;
2720
import java.util.Properties;
2821

2922
public class MavenWrapperDownloader {
3023

24+
private static final String WRAPPER_VERSION = "0.5.6";
3125
/**
3226
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
3327
*/
34-
private static final String DEFAULT_DOWNLOAD_URL =
35-
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
28+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
29+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
3630

3731
/**
3832
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
@@ -80,13 +74,13 @@ public static void main(String args[]) {
8074
}
8175
}
8276
}
83-
System.out.println("- Downloading from: : " + url);
77+
System.out.println("- Downloading from: " + url);
8478

8579
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
8680
if (!outputFile.getParentFile().exists()) {
8781
if (!outputFile.getParentFile().mkdirs()) {
8882
System.out.println(
89-
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
9084
}
9185
}
9286
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
@@ -102,6 +96,16 @@ public static void main(String args[]) {
10296
}
10397

10498
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
99+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
100+
String username = System.getenv("MVNW_USERNAME");
101+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
102+
Authenticator.setDefault(new Authenticator() {
103+
@Override
104+
protected PasswordAuthentication getPasswordAuthentication() {
105+
return new PasswordAuthentication(username, password);
106+
}
107+
});
108+
}
105109
URL website = new URL(urlString);
106110
ReadableByteChannel rbc;
107111
rbc = Channels.newChannel(website.openStream());
2.32 KB
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

Spring-Boot-JdbcTemplate/mvnw

Lines changed: 29 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Spring-Boot-JdbcTemplate/mvnw.cmd

Lines changed: 32 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Spring-Boot-JdbcTemplate/pom.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.1.3.RELEASE</version>
8+
<version>2.2.5.RELEASE</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>com.example</groupId>
@@ -23,27 +23,29 @@
2323
<groupId>org.springframework.boot</groupId>
2424
<artifactId>spring-boot-starter-web</artifactId>
2525
</dependency>
26-
2726
<dependency>
2827
<groupId>org.springframework.boot</groupId>
2928
<artifactId>spring-boot-starter-jdbc</artifactId>
3029
</dependency>
31-
3230
<dependency>
3331
<groupId>mysql</groupId>
3432
<artifactId>mysql-connector-java</artifactId>
3533
</dependency>
36-
3734
<dependency>
3835
<groupId>com.alibaba</groupId>
3936
<artifactId>druid-spring-boot-starter</artifactId>
40-
<version>1.1.10</version>
37+
<version>1.1.21</version>
4138
</dependency>
42-
4339
<dependency>
4440
<groupId>org.springframework.boot</groupId>
4541
<artifactId>spring-boot-starter-test</artifactId>
4642
<scope>test</scope>
43+
<exclusions>
44+
<exclusion>
45+
<groupId>org.junit.vintage</groupId>
46+
<artifactId>junit-vintage-engine</artifactId>
47+
</exclusion>
48+
</exclusions>
4749
</dependency>
4850
</dependencies>
4951

Spring-Boot-JdbcTemplate/src/main/java/com/example/jdbctemplate/controller/TestController.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import com.example.jdbctemplate.bean.Student;
44
import com.example.jdbctemplate.service.StudentService;
55
import org.springframework.beans.factory.annotation.Autowired;
6-
import org.springframework.web.bind.annotation.RequestMapping;
7-
import org.springframework.web.bind.annotation.RequestMethod;
8-
import org.springframework.web.bind.annotation.RestController;
6+
import org.springframework.web.bind.annotation.*;
97

108
import java.util.List;
119
import java.util.Map;
@@ -18,27 +16,28 @@ public class TestController {
1816
@Autowired
1917
private StudentService studentService;
2018

21-
@RequestMapping(value = "/querystudent", method = RequestMethod.GET)
22-
public Student queryStudentById(String sno) {
19+
@GetMapping("/querystudent/{sno}")
20+
public Student queryStudentById(@PathVariable String sno) {
2321
return this.studentService.queryStudentBySno(sno);
2422
}
2523

26-
@RequestMapping(value = "/queryallstudent")
24+
@GetMapping("/queryallstudent")
2725
public List<Map<String, Object>> queryAllStudent() {
2826
return this.studentService.queryStudentListMap();
2927
}
3028

31-
@RequestMapping(value = "/addstudent", method = RequestMethod.GET)
32-
public int saveStudent(String sno, String name, String sex) {
33-
Student student = new Student();
34-
student.setSno(sno);
35-
student.setName(name);
36-
student.setSex(sex);
29+
@PostMapping("/addstudent")
30+
public int saveStudent(@RequestBody Student student) {
3731
return this.studentService.add(student);
3832
}
3933

40-
@RequestMapping(value = "deletestudent", method = RequestMethod.GET)
41-
public int deleteStudentById(String sno) {
34+
@PutMapping("/updatestudent")
35+
public int updatestudent(@RequestBody Student student){
36+
return this.studentService.update(student);
37+
}
38+
39+
@DeleteMapping("/deletestudent/{sno}")
40+
public int deleteStudentById(@PathVariable String sno) {
4241
return this.studentService.deleteBysno(sno);
4342
}
4443
}

Spring-Boot-JdbcTemplate/src/main/java/com/example/jdbctemplate/mapper/impl/StudentMapperImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.sql.Types;
1313
import java.util.List;
1414
import java.util.Map;
15+
import java.util.Objects;
1516

1617
/**
1718
* Created by dengzhiming on 2019/3/24
@@ -30,7 +31,7 @@ public int add(Student student) {
3031
// return this.jdbcTemplate.update(sql, args, argTypes);
3132
// 较多字段使用: NamedParameterJdbcTemplate; 返回结果,可直接使用List<Map<String, Object>>来接收
3233
String sql = "insert into student(sno,sname,ssex) values(:sno,:name,:sex)";
33-
NamedParameterJdbcTemplate npjt = new NamedParameterJdbcTemplate(this.jdbcTemplate.getDataSource());
34+
NamedParameterJdbcTemplate npjt = new NamedParameterJdbcTemplate(Objects.requireNonNull(this.jdbcTemplate.getDataSource()));
3435
return npjt.update(sql, new BeanPropertySqlParameterSource(student));
3536
}
3637

@@ -62,7 +63,7 @@ public Student queryStudentBySno(String sno) {
6263
Object[] args = {sno};
6364
int[] argTypes = {Types.VARCHAR};
6465
List<Student> studentList = this.jdbcTemplate.query(sql, args, argTypes, new StudentObj());
65-
if (studentList != null && studentList.size() > 0) {
66+
if (studentList.size() > 0) {
6667
return studentList.get(0);
6768
} else {
6869
return null;

Spring-Boot-JdbcTemplate/src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

Spring-Boot-JdbcTemplate/src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ spring:
6060
# 配置StatFilter
6161
filter:
6262
stat:
63-
log-slow-sql: true
63+
log-slow-sql: true

0 commit comments

Comments
 (0)