202009-24 Springboot和Jpa实现学生CRUD操作代码实例 前期准备使用idea新建个SpringBoot项目在数据库中建student表建包1.编写entity包下实体类Student(一个Javabean规范)packagecom.example.stu.kudestu.stu.entity;importjavax.persistence.*;@Entity@Table(name="student")//@Entity应用在实体类上@Table(name="student")应用在实体类上,并且name属性为数据库表名publicclassStudent{@Id@GeneratedValue(strategy=GenerationType.IDENTITY)//ID自增private... 继续阅读 >
202009-24 SpringBoot如何使用Fastjson解析Json数据 方法一:1.在pom.xml文件下添加依赖包<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.15</version></dependency>2.修改启动文件packagemyshop;importjava.util.List;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.http.converter.HttpMessageConverter;importo... 继续阅读 >
202009-24 SpringBoot实现devtools实现热部署过程解析 1.修改pom.xml文件<project><dependencies><!--使用devtool热部署插件(推荐)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional><scope>true</scope></dependency></dependencies><build><finalName>myshop</finalName><!--热部署插件--><plugins><plugin><groupId>org.springframewo... 继续阅读 >
202009-24 SpringBoot热部署Springloaded实现过程解析 为啥要热部署:在修改代码的时候,不需要重新启动程序,程序会自动进行编译注意:控制器中新增加的方法是不能进行热部署的方法:1.在pom.xml文件里面添加下面代码<project><build><finalName>myshop</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>2.右键项目-》“properties”-... 继续阅读 >
202009-24 SpringBoot thymeleaf的使用方法解析 1.pom.xml添加相应依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>2.application.properties#thymeleafspring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.htmlspring.thymeleaf.mode=HTML5spring.thymeleaf.encoding=UTF-8spring.thymeleaf.content-type=text/html;charset=utf-8spring.thymeleaf.cache=false3... 继续阅读 >
202009-24 SpringBoot如何集成PageHelper分页功能 添加MyBatis的代码并修改以下部分:1.添加MyBatisConfigpackagemyshop.config;importjava.util.Properties;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importcom.github.pagehelper.PageHelper;@ConfigurationpublicclassMyBatisConfig{@BeanpublicPageHelperpageHelper(){System.out.println("UsePageHelper");PageHelperpageHelp... 继续阅读 >
202009-24 Springboot es包版本异常解决方案 在项目pom.xml中加入依赖<dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId><version>7.6.1</version></dependency><dependency><groupId>org.elasticsearch</groupId><artifactId>elasticsearch</artifactId><version>7.6.1</version></dependency>发现项目总会拉下6.4.3的版本,并且项目中也会引用这个版本然后启动项目,还会发现找不到方法... 继续阅读 >
202009-24 SpringBoot个性化启动Banner设置方法解析 1.添加Banner.txt文件._________/\\/___'_____(_)______\\\\(()\___|'_|'_||'_\/_`|\\\\\\/___)||_)|||||||(_||))))'|____|.__|_||_|_||_\__,|////=========|_|==============|___/=/_/_/_/::tianhengSpringBoot::(v2.0.5.RELEASE)2.修改application.properties文件#端口号server.port=8090#配置bannner地址spring.banner.location=banner.txt3.添... 继续阅读 >
202009-24 SpringBoot Maven Clean报错解决方案 报错信息:Pluginorg.apache.maven.plugins:maven-clean-plugin:3.0.0oroneofitsdependenciescouldnotberesolved解决方法:修改pom.xml下:<version>0.0.1-SNAPSHOT</version>为<version>0.0.1</version>另附:可能Problem窗体下回给出错误提示(警告不用管),直接右键删除即可,不然有报错提示MavenClean会不成功以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自学编程网。... 继续阅读 >
202009-24 SpringBoot将项目打成war包步骤解析 1.修改pom.xml文件<projectxmlns="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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>top.ytheng</groupId><artifactId>springboot-demo</artifactId><version>0.0.1</version><packaging>war</packaging><parent><groupI... 继续阅读 >
202009-24 SpringBoot拦截器Filter的使用方法详解 前言:最新Servlet3.0拦截器的使用1.pom.xml添加需要使用的依赖<projectxmlns="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.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>top.ytheng</groupId><artifactId>springboot-demo</artifactId><version>0.0.1</version><pac... 继续阅读 >
202009-24 SpringBoot异步任务使用方法详解 步骤,如图所示:1.添加异步任务业务类packagetop.ytheng.demo.task;importjava.util.concurrent.Future;importorg.springframework.scheduling.annotation.Async;importorg.springframework.scheduling.annotation.AsyncResult;importorg.springframework.stereotype.Component;//异步任务业务类@Component//标记此类是异步类,也可在方法中标记//不加,则类里面的方法为同步执行@AsyncpublicclassAsyncTask{publicvoi... 继续阅读 >
202009-24 SpringBoot整合MybatisSQL过滤@Intercepts的实现 场景:系统模块查询数据库需要根据用户的id去筛选数据。那么如果在每个sql加user_id的过滤显然不明确。所以要在查询前将sql拼接上条件,做统一管理。开发环境:springboot+mybatis只需一个拦截类即可搞定(在看代码前需要了解注解@Intercepts()):@Component@Intercepts({@Signature(type=Executor.class,method="query",args={MappedStatement.class,Object.class,RowBounds.class,ResultHandler.class})})pub... 继续阅读 >
202009-24 Springboot通过aop实现事务控制过程解析 spring的事务控制本质上是通过aop实现的。在springboot中使用时,可以通过注解@Transactional进行类或者方法级别的事务控制,也可以自己通过spring提供的事务管理器手动控制事务一、@Transactional注解进行进行类或者方法级别的事务控制不需要进行特别的设置,按照正常的配置整合spring和mybatis后,在需要进行事务控制的类上或者方法上加上@Transactional注解,即可对其进行事务控制。二、手动控制事务当需要在一个方法的内部进行... 继续阅读 >
202009-24 SpringBoot logback日志框架使用过程解析 一、基本知识说明SpringBoot默认使用logback作为日志框架,所以引入起步依赖后就可以直接使用logback,不需要其他依赖。SpringBoot会默认加载classpath:logback.xml或者classpath:logback-spring.xml作为日志的配置文件,在springboot项目中可以直接把日志配置文件放在resources目录下。简单使用时也可以不使用日志配置文件,将日志相关的配置直接放在application.yml中,如下#日志设置logging:file:root.loglevel:com:lyy:dao:deb... 继续阅读 >
202009-24 vue+springboot前后端分离工程跨域问题解决方案解析 假如是在同一台机器上开发,前后端分离的工程中出现跨域问题的原因是,前端工程和后端工程运行在不同的端口上。只要协议、域名、端口有一个不同就会产生跨域问题,所以在前端工程中请求后端的接口时就会因为端口不同而产生跨域问题。一、解决跨域的原理假设前端A要去访问服务器C,可以在A和C之间之间设置一个代理B,A访问C时先访问B,再由B代为请求C并把请求结果返回给A,这样就可以解决跨域问题。其中需要保证的是A访问B和B访问C都... 继续阅读 >