-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.neo</groupId> | ||
<artifactId>spring-boot-web</artifactId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
|
||
<name>spring-boot-web</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.0.0</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>17</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.webjars.bower</groupId> | ||
<artifactId>jquery</artifactId> | ||
<version>2.0.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.webjars.bower</groupId> | ||
<artifactId>bootstrap</artifactId> | ||
<version>3.0.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
12 changes: 12 additions & 0 deletions
12
3.x/spring-boot-web/src/main/java/com/neo/WebApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.neo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class WebApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(WebApplication.class, args); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
3.x/spring-boot-web/src/main/java/com/neo/WebConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.neo; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.servlet.Filter; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.FilterConfig; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.ServletRequest; | ||
import jakarta.servlet.ServletResponse; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
|
||
import org.apache.catalina.filters.RemoteIpFilter; | ||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class WebConfiguration { | ||
@Bean | ||
public RemoteIpFilter remoteIpFilter() { | ||
return new RemoteIpFilter(); | ||
} | ||
|
||
@Bean | ||
public FilterRegistrationBean testFilterRegistration() { | ||
|
||
FilterRegistrationBean registration = new FilterRegistrationBean(); | ||
registration.setFilter(new MyFilter()); | ||
registration.addUrlPatterns("/*"); | ||
registration.addInitParameter("paramName", "paramValue"); | ||
registration.setName("MyFilter"); | ||
registration.setOrder(1); | ||
return registration; | ||
} | ||
|
||
public class MyFilter implements Filter { | ||
@Override | ||
public void destroy() { | ||
// TODO Auto-generated method stub | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain filterChain) | ||
throws IOException, ServletException { | ||
// TODO Auto-generated method stub | ||
HttpServletRequest request = (HttpServletRequest) srequest; | ||
System.out.println("this is MyFilter,url :"+request.getRequestURI()); | ||
filterChain.doFilter(srequest, sresponse); | ||
} | ||
|
||
@Override | ||
public void init(FilterConfig arg0) throws ServletException { | ||
// TODO Auto-generated method stub | ||
} | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.neo.model; | ||
|
||
import java.io.Serializable; | ||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
public class User implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
@Column(nullable = false, unique = true, length = 20) | ||
private String userName; | ||
@Column(nullable = false) | ||
private String passWord; | ||
@Column(nullable = false, unique = true, length = 30) | ||
private String email; | ||
@Column(nullable = true, unique = true, length = 30) | ||
private String nickName; | ||
@Column(nullable = false) | ||
private String regTime; | ||
|
||
public User() { | ||
super(); | ||
} | ||
public User(String nickName,String email,String userName, String passWord, String regTime) { | ||
super(); | ||
this.email = email; | ||
this.nickName = nickName; | ||
this.passWord = passWord; | ||
this.userName = userName; | ||
this.regTime = regTime; | ||
} | ||
public Long getId() { | ||
return id; | ||
} | ||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
public String getUserName() { | ||
return userName; | ||
} | ||
public void setUserName(String userName) { | ||
this.userName = userName; | ||
} | ||
public String getPassWord() { | ||
return passWord; | ||
} | ||
public void setPassWord(String passWord) { | ||
this.passWord = passWord; | ||
} | ||
public String getEmail() { | ||
return email; | ||
} | ||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
public String getNickName() { | ||
return nickName; | ||
} | ||
public void setNickName(String nickName) { | ||
this.nickName = nickName; | ||
} | ||
public String getRegTime() { | ||
return regTime; | ||
} | ||
public void setRegTime(String regTime) { | ||
this.regTime = regTime; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
3.x/spring-boot-web/src/main/java/com/neo/repository/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.neo.repository; | ||
|
||
import com.neo.model.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
|
||
User findByUserName(String userName); | ||
|
||
User findByUserNameOrEmail(String username, String email); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
3.x/spring-boot-web/src/main/java/com/neo/util/NeoProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.neo.util; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NeoProperties { | ||
|
||
@Value("${com.neo.title}") | ||
private String title; | ||
@Value("${com.neo.description}") | ||
private String description; | ||
public String getTitle() { | ||
return title; | ||
} | ||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
public String getDescription() { | ||
return description; | ||
} | ||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
3.x/spring-boot-web/src/main/java/com/neo/web/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.neo.web; | ||
|
||
import java.util.Locale; | ||
import java.util.UUID; | ||
|
||
import jakarta.servlet.http.HttpSession; | ||
|
||
import com.neo.model.User; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HelloController { | ||
|
||
@RequestMapping("/hello") | ||
public String hello(Locale locale, Model model) { | ||
return "Hello World"; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
3.x/spring-boot-web/src/main/java/com/neo/web/ThymeleafController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.neo.web; | ||
|
||
import java.text.DateFormat; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
public class ThymeleafController { | ||
|
||
@RequestMapping("/hi") | ||
public String hello(Locale locale, Model model) { | ||
model.addAttribute("greeting", "Hello!"); | ||
|
||
Date date = new Date(); | ||
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); | ||
String formattedDate = dateFormat.format(date); | ||
model.addAttribute("currentTime", formattedDate); | ||
|
||
return "hello"; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
3.x/spring-boot-web/src/main/java/com/neo/web/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.neo.web; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.neo.model.User; | ||
import com.neo.repository.UserRepository; | ||
|
||
@RestController | ||
public class UserController { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@RequestMapping("/add") | ||
public User saveUser(String key) { | ||
User user=new User(); | ||
user.setUserName("aa"+key); | ||
user.setEmail("ityouknow@126.com"+key); | ||
user.setNickName("微笑"+key); | ||
user.setPassWord("123456"+key); | ||
user.setRegTime("2022-12-20"+key); | ||
userRepository.save(user); | ||
return user; | ||
} | ||
|
||
@RequestMapping("/getUser") | ||
public User getUser() { | ||
User user=userRepository.findByUserName("aa"); | ||
System.out.println("若下面没出现“无缓存的时候调用”字样且能打印出数据表示测试成功"); | ||
return user; | ||
} | ||
|
||
@RequestMapping("/getUsers") | ||
public List<User> getUsers() { | ||
List<User> users=userRepository.findAll(); | ||
System.out.println("若下面没出现“无缓存的时候调用”字样且能打印出数据表示测试成功"); | ||
return users; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
3.x/spring-boot-web/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
spring.datasource.url=jdbc:mysql://174.137.48.31:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true | ||
spring.datasource.username=itmooc_tech | ||
spring.datasource.password=e8tEzFMApR | ||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver | ||
# ???????? | ||
spring.datasource.hikari.maxLifeTime=600000 | ||
|
||
spring.jpa.properties.hibernate.hbm2ddl.auto=create | ||
#sql\u8F93\u51FA | ||
spring.jpa.show-sql=true | ||
#format\u4E00\u4E0Bsql\u8FDB\u884C\u8F93\u51FA | ||
spring.jpa.properties.hibernate.format_sql=true | ||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect | ||
spring.jpa.open-in-view=false | ||
|
||
com.neo.title=\u7EAF\u6D01\u7684\u5FAE\u7B11 | ||
com.neo.description=\u5206\u4EAB\u751F\u6D3B\u548C\u6280\u672F |
8 changes: 8 additions & 0 deletions
8
3.x/spring-boot-web/src/main/resources/static/css/starter.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body { | ||
padding-top: 50px; | ||
} | ||
|
||
.starter-template { | ||
padding: 40px 15px; | ||
text-align: center; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.