IntelliJ IDEA Spring Boot:修订间差异
跳到导航
跳到搜索
(→参考) |
无编辑摘要 |
||
(未显示同一用户的5个中间版本) | |||
第1行: | 第1行: | ||
Spring Boot | Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss. It takes an opinionated view of the Spring platform so that new and existing users can quickly get to the bits they need. | ||
* | Spring Boot 是一个基于 Spring 的框架,旨在简化 Spring 应用的配置和开发过程,通过自动配置和约定大于配置的原则,使开发者能够快速搭建独立、生产级别的应用程序。 | ||
* | * Environment: IntelliJ IDEA 2023.1 (Ultimate Edition) | ||
* | * Features: web, mysql | ||
* Course: | |||
# New project -> Spring Initializr -> type: maven: testSprintBoot | # New project -> Spring Initializr -> type: maven: testSprintBoot | ||
# Dependency -> Web: Spring Web,SQL: MyBatis Framework, MySQL Driver/H2 Database | # Dependency -> Web: Spring Web,SQL: MyBatis Framework, MySQL Driver/H2 Database | ||
第9行: | 第10行: | ||
# src/main/resources/static: index.html | # src/main/resources/static: index.html | ||
# com.example.testspringboot: bean, controller, mapper, service | # com.example.testspringboot: bean, controller, mapper, service | ||
=== pom.xml === | |||
<small><nowiki><!-- spring-boot --> | |||
<parent> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-parent</artifactId> | |||
<version>3.3.2</version> | |||
<relativePath/> | |||
</parent> | |||
<dependencies> | |||
<!-- spring-boot --> | |||
<dependency> | |||
<groupId>org.springframework.boot</groupId> | |||
<artifactId>spring-boot-starter-web</artifactId> | |||
</dependency> | |||
<!-- mybatis --> | |||
<dependency> | |||
<groupId>org.mybatis.spring.boot</groupId> | |||
<artifactId>mybatis-spring-boot-starter</artifactId> | |||
<version>3.0.3</version> | |||
</dependency> | |||
<!-- MySQL --> | |||
<dependency> | |||
<groupId>com.mysql</groupId> | |||
<artifactId>mysql-connector-java</artifactId> | |||
<version>8.0.33</version> | |||
</dependency> | |||
</dependencies></nowiki></small> | |||
=== application.yml === | === application.yml === | ||
第22行: | 第52行: | ||
password: 123456 | password: 123456 | ||
driver-class-name: com.mysql.cj.jdbc.Driver | driver-class-name: com.mysql.cj.jdbc.Driver | ||
mybatis: | mybatis: | ||
type-aliases-package: com.example.testspringboot.bean</nowiki></small> | type-aliases-package: com.example.testspringboot.bean</nowiki></small> | ||
=== index.html === | === index.html === | ||
第38行: | 第66行: | ||
This is a test web page. | This is a test web page. | ||
</body> | </body> | ||
</html> | </html></nowiki></small> | ||
# main.java/com.example.testspringboot.TestspringbootApplication | === TestSprintBootApplication === | ||
<small><nowiki># main.java/com.example.testspringboot.TestspringbootApplication | |||
package com.example.testspringboot; | package com.example.testspringboot; | ||
第50行: | 第79行: | ||
public static void main(String[] args) { | public static void main(String[] args) { | ||
SpringApplication.run(TestspringbootApplication.class, args); | SpringApplication.run(TestspringbootApplication.class, args); | ||
} | } | ||
}</nowiki></small> | }</nowiki></small> | ||
第132行: | 第148行: | ||
public List<SysUser> selectAll(); | public List<SysUser> selectAll(); | ||
} | } | ||
# service: SysUserServiceImpl | # service: SysUserServiceImpl | ||
第184行: | 第199行: | ||
=== Test === | === Test === | ||
<small><nowiki>http:// | <small><nowiki>http://127.0.0.1:8083/sysuser/selectAll | ||
[{"host":"%","user":"root","passwordLastChanged":null},{"host":"localhost","user":"mysql.infoschema","passwordLastChanged":null},{"host":"localhost","user":"mysql.session","passwordLastChanged":null},{"host":"localhost","user":"mysql.sys","passwordLastChanged":null},{"host":"localhost","user":"root","passwordLastChanged":null}]</nowiki></small> | [{"host":"%","user":"root","passwordLastChanged":null},{"host":"localhost","user":"mysql.infoschema","passwordLastChanged":null},{"host":"localhost","user":"mysql.session","passwordLastChanged":null},{"host":"localhost","user":"mysql.sys","passwordLastChanged":null},{"host":"localhost","user":"root","passwordLastChanged":null}]</nowiki></small> | ||
== See also == | |||
== | |||
# [https://www.cnblogs.com/detailNew/p/14967528.html IDEA搭建一个SpringBoot项目] | # [https://www.cnblogs.com/detailNew/p/14967528.html IDEA搭建一个SpringBoot项目] | ||
# [https://www.cnblogs.com/caizhaokai/p/10982727.html SpringBoot + MyBatis(注解版),常用的SQL方法] | # [https://www.cnblogs.com/caizhaokai/p/10982727.html SpringBoot + MyBatis(注解版),常用的SQL方法] | ||
# [https://springdoc.cn/spring-and-cors/ 在 Spring 应用中处理 CORS 跨域] | |||
[[分类:Develop]] | [[分类:Develop]] | ||
[[分类:Java]] | [[分类:Java]] |
2024年10月24日 (四) 10:22的最新版本
Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss. It takes an opinionated view of the Spring platform so that new and existing users can quickly get to the bits they need.
Spring Boot 是一个基于 Spring 的框架,旨在简化 Spring 应用的配置和开发过程,通过自动配置和约定大于配置的原则,使开发者能够快速搭建独立、生产级别的应用程序。
- Environment: IntelliJ IDEA 2023.1 (Ultimate Edition)
- Features: web, mysql
- Course:
- New project -> Spring Initializr -> type: maven: testSprintBoot
- Dependency -> Web: Spring Web,SQL: MyBatis Framework, MySQL Driver/H2 Database
- src/main/resources: application.properties -> application.yml
- src/main/resources/static: index.html
- com.example.testspringboot: bean, controller, mapper, service
pom.xml
<!-- spring-boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.3.2</version> <relativePath/> </parent> <dependencies> <!-- spring-boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>3.0.3</version> </dependency> <!-- MySQL --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.33</version> </dependency> </dependencies>
application.yml
spring.application.name: testSprintBoot server: port: 8083 spring: datasource: url: jdbc:mysql://192.168.0.83:3306/mysql?serverTimezone=Asia/Shanghai&characterEncoding=utf-8 username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver mybatis: type-aliases-package: com.example.testspringboot.bean
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> This is a test web page. </body> </html>
TestSprintBootApplication
# main.java/com.example.testspringboot.TestspringbootApplication package com.example.testspringboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class TestspringbootApplication { public static void main(String[] args) { SpringApplication.run(TestspringbootApplication.class, args); } }
bean
SysUser
package com.example.testsprintboot.bean; import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; import java.util.Date; public class SysUser { private String host; private String user; private String passwordLastChanged; public String getHost() { return host; } public void setHost(String host) { this.host = host; } public String getUser() { return user; } public void setUser(String user) { this.user = user; } public String getPasswordLastChanged() { return passwordLastChanged; } public void setPasswordLastChanged(String passwordLastChanged) { this.passwordLastChanged = passwordLastChanged; } }
mapper
SysUserMapper
package com.example.testsprintboot.mapper; import com.example.testsprintboot.bean.SysUser; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import java.util.List; @Mapper public interface SysUserMapper { @Select({ "select", "host, user, date_format(password_last_changed, '%Y-%m-%d %H:%i:%s') password_last_changed", "from user" }) List<SysUser> selectAll(); }
service
SysUserService
package com.example.testsprintboot.service; import com.example.testsprintboot.bean.SysUser; import java.util.List; public interface SysUserService { public List<SysUser> selectAll(); } # service: SysUserServiceImpl package com.example.testsprintboot.service; import com.example.testsprintboot.bean.SysUser; import com.example.testsprintboot.mapper.SysUserMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service("SysUserService") public class SysUserServiceImpl implements SysUserService { @Autowired private SysUserMapper sysUserMapper; @Override public List<SysUser> selectAll() { return sysUserMapper.selectAll(); } }
controller
SysUserController
package com.example.testsprintboot.controller; import com.example.testsprintboot.bean.SysUser; import com.example.testsprintboot.service.SysUserService; import com.example.testsprintboot.service.SysUserServiceImpl; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import jakarta.annotation.Resource; import java.util.List; @RestController @RequestMapping("/sysuser") public class SysUserController { @Resource private SysUserService sysUserService = new SysUserServiceImpl(); @RequestMapping(value = "/selectAll", method = RequestMethod.GET) public List<SysUser> selectAll() { List<SysUser> list = sysUserService.selectAll(); return list; } }
Test
http://127.0.0.1:8083/sysuser/selectAll [{"host":"%","user":"root","passwordLastChanged":null},{"host":"localhost","user":"mysql.infoschema","passwordLastChanged":null},{"host":"localhost","user":"mysql.session","passwordLastChanged":null},{"host":"localhost","user":"mysql.sys","passwordLastChanged":null},{"host":"localhost","user":"root","passwordLastChanged":null}]