当前位置: 首页 > news >正文

农村电商网站有哪些提高seo关键词排名

农村电商网站有哪些,提高seo关键词排名,wordpress 导出到pdf,泉州网站设计招聘网目录 一、springboot的应用 1、创建springboot项目 2、乱码问题配置 3、springboot日志配置 4、springboot整合mybatis 二、配置文件讲解及测试 1、全局配置文件参数读取 1.1 全局配置文件的位置 1.2 配置文件的读取 1.2.1 导包 1.2.2 编写配置对象Bean 1.2.3 编写配置文件 1.2…

目录

一、springboot的应用

1、创建springboot项目

2、乱码问题配置

3、springboot日志配置

4、springboot整合mybatis

二、配置文件讲解及测试

1、全局配置文件参数读取

1.1 全局配置文件的位置

1.2 配置文件的读取

1.2.1 导包

1.2.2 编写配置对象Bean

1.2.3 编写配置文件

1.2.3.1 properties文件方式

1.2.3.2 yml(yaml)文件方式

1.2.4 单测

2、四种属性注入方式

2.1 单个属性绑定@Value

2.2 批量属性绑定@ConfigurationProperties

2.3 第三方进行属性绑定@Bean

3、热部署


一、springboot的应用

1、创建springboot项目

将项目主程序启动类SpringbootTestApplication放到com.test目录下
创建src/main/java/com/test/controller/DemoController.java
@RestController // 该注解为组合注解,等同于Spring中@Controller+@ResponseBody注解
public class DemoController {@RequestMapping("/demo")public String demo(){System.out.println("你好");return "hello springBoot";}
}
启动项目: SpringbootTestApplication. main
访问网址: http://localhost:8080/demo

2、乱码问题配置

application,properties添加配置
# 乱码问题配置
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.enabled=true
server.servlet.encoding.force=true

3、springboot日志配置

导包
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><artifactId>spring-boot-starter-logging</artifactId><groupId>org.springframework.boot</groupId></exclusion></exclusions>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
配置log的形式
src/main/resources/application.properties
# 日志配置
# 指定具体包的日志级别
logging.level.com.test=debug
# 控制台和日志文件输出格式
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level%logger{50} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}- %msg%n
# 日志输出路径,默认文件spring.log
logging.file.path=spring.log
#logging.file.name=log.log
单测:
@SpringBootTest
public class LoggerTests {Logger logger = LoggerFactory.getLogger(getClass());@Testpublic void testLog() {logger.trace("Trace 日志...");logger.debug("Debug 日志...");logger.info("Info 日志...");logger.warn("Warn 日志...");logger.error("Error 日志...");}
}

4、springboot整合mybatis

导包
<!-- 配置处理器-配置文件参数注入 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional>
</dependency>
<!-- 配置mysql数据驱动 -->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.25</version>
</dependency>
<!-- druid连接池 -->
<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.10</version>
</dependency>
<!-- 整合jdbc -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- 整合mybatis -->
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.3</version>
</dependency>
配置数据库连接
src/main/resources/application.yml
spring:datasource:username: rootpassword: rooturl: jdbc:mysql://192.168.3.33:3306/springimpl?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTCdriver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSourceinitialSize: 5minIdle: 5maxActive: 20maxWait: 60000timeBetweenEvictionRunsMillis: 60000minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1 FROM DUALtestWhileIdle: truetestOnBorrow: falsetestOnReturn: falsepoolPreparedStatements: truemaxPoolPreparedStatementPerConnectionSize: 20useGlobalDataSourceStat: trueconnectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500sql:init:mode: always
编写整合 druid 的配置类 DruidConfig:为了使dataSource的非核心参数注入
@Configuration
public class DruidConfig {@Bean@ConfigurationProperties(prefix = "spring.datasource")public DataSource druid(){return new DruidDataSource();}
}
基础pojo
src/main/java/com/test/pojo/User.java
public class User {private Integer id;private String username;private String password;//省略set、get、toString
}

编写Mapper

src/main/java/com/test/mapper/UserMapper.java

public interface UserMapper {@Select("SELECT * FROM USER")List<User> findList();
}
在启动类上加扫描配置
@SpringBootApplication
@MapperScan("com.test.mapper")
public class SpringbootTestApplication {public static void main(String[] args) {SpringApplication.run(SpringbootTestApplication.class, args);}
}

编写service
src/main/java/com/test/service/UserService.java
@Service
public class UserService {Logger logger = LoggerFactory.getLogger(UserService.class);@Autowiredprivate UserMapper userMapper;public List<User> findUsers(){List<User> userList = userMapper.findList();logger.info(userList.toString());return userList;}
}
单测
@SpringBootTest
public class MybatisTests {@Autowiredprivate UserService userService;@Testpublic void getUser() {userService.findUsers();}
}

二、配置文件讲解及测试

1、全局配置文件参数读取

1.1 全局配置文件的位置

全局配置文件可以在四个位置,其优先级高低的顺序为:
1. 先去项目根目录找config文件夹下找配置文件件
2. 再去根目录下找配置文件
3. 去resources下找cofnig文件夹下找配置文件
4. 去resources下找配置文件
配置文件中属性:
如果不冲突,则会共同存在-互补配置
如果冲突,默认使用第1个读取到的
如果配置文件的名称不叫application.properties或者application.yml,可以通过以下参数来指定 配置文件的名字,myproject是配置文件名
java -jar myproject.jar --spring.config.name=myproject
也可以指定其他位置的配置文件 和 默认加载的配置文件共同起作用
java -jar run-0.0.1-SNAPSHOT.jar --spring.config.location=D:/application.properties

1.2 配置文件的读取

配置文件有两种方式: application.properties application.yml
2.4.0之前版本,优先级properties>yaml
2.4.0及以后的版本,优先级yaml>properties
如果想继续使用 Spring Boot 2.3 的配置逻辑,也可以通过在 application.properties 或者  application.yml 配置文件中添加以下参数:
spring.config.use-legacy-processing = true
1.2.1 导包
<!-- 配置处理器 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional>
</dependency>
1.2.2 编写配置对象Bean
创建对象
src/main/java/com/test/pojo/Pet.java
public class Pet {private String type;private String name;//省略get、set、tostring
}
src/main/java/com/test/pojo/Person.java
@Component //用于将Person类作为Bean注入到Spring容器中
@ConfigurationProperties(prefix = "person") //将配置文件中以person开头的属性注入到该类中
public class Person {private int id; //idprivate String name; //名称private List hobby; //爱好private String[] family; //家庭成员private Map map;private Pet pet; //宠物//省略get、set、tostring
}
1.2.3 编写配置文件
1.2.3.1 properties文件方式
src/main/resources/application.properties
person.id=1
person.name=tom
person.hobby=吃饭,睡觉
person.family=大哥,大姐
person.map.k1=v1
person.map.k2=v2
person.pet.name=大白
person.pet.type=dog
1.2.3.2 yml(yaml)文件方式
YAML 文件格式是 Spring Boot 支持的一种 JSON 超集文件格式,以数据为中心,比 properties xml 等更 适合做配置文件
使用 “key: (空格) value” 格式配置属性,使用缩进控制层级关系
src/main/resources/application.yml
#对实体类对象Person进行属性配置
person:id: 1name: lucyhobby: [吃饭,睡觉]family: [father,mother]map: {k1: v1,k2: v2}pet: {type: dog,name: 旺财}
1.2.4 单测
src/test/java/com/test/springboottest/SpringbootTestApplicationTests.java
@SpringBootTest
class SpringbootTestApplicationTests {@Autowiredprivate Person person;@Testvoid contextLoads() {System.out.println(person);}
}

2、四种属性注入方式

注意,当配置文件不是默认配置文件名时:
@PropertySource("classpath:/jdbc.properties") 指定外部属性文件。在类上添加
添加默认配置信息
src/main/resources/application.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/springboot
jdbc.username=root
jdbc.password=123

2.1 单个属性绑定@Value

@Configuration:声明一个类作为配置类
@Value:属性注入
配置类
src/main/java/com/test/config/JdbcConfiguration.java
@Configuration
public class JdbcConfiguration {@Value("${jdbc.url}")String url;@Value("${jdbc.driverClassName}")String driverClassName;@Value("${jdbc.username}")String username;@Value("${jdbc.password}")String password;
}
单测:
@Autowired
private JdbcConfiguration jdbcConfiguration;
@Test
void test01() {System.out.println(jdbcConfiguration);
}

2.2 批量属性绑定@ConfigurationProperties

@Configuration:声明一个类作为配置类
@EnableConfigurationProperties:用于启用应用对另外一个注解 @ConfigurationProperties的支持
@ConfigurationProperties(prefix = "jdbc"):批量属性注入
导包
<!-- 配置处理器 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional>
</dependency>
配置类
src/main/java/com/test/config/JdbcConfiguration.java
@Configuration
@EnableConfigurationProperties(JdbcConfiguration.class)
@ConfigurationProperties(prefix = "jdbc")
public class JdbcConfiguration {String url;String driverClassName;String username;String password;//省略set、get、toString
}
单测:
@Autowired
private JdbcConfiguration jdbcConfiguration;
@Test
void test01() {System.out.println(jdbcConfiguration);
}

2.3 第三方进行属性绑定@Bean

将属性绑定到控件之外的第三方组件
@Configuration:声明一个类作为配置类
@ConfigurationProperties(prefix = "jdbc"):批量属性注入
@Bean:声明在方法上,将方法的返回值加入Bean容器
导包
<!-- 配置处理器 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional>
</dependency>
添加配置信息
src/main/resources/application.properties
another.enabled=true
another.remoteAddress=192.168.10.11
创建一个其他组件类
src/main/java/com/test/config/AnotherComponent.java
public class AnotherComponent {private boolean enabled;private InetAddress remoteAddress;//省略set、get、toString
}
创建绑定类
@Configuration
public class MyService {@ConfigurationProperties("another")@Beanpublic AnotherComponent anotherComponent(){return new AnotherComponent();}
}
单测
@Autowired
private AnotherComponent anotherComponent;
@Test
void test02() {System.out.println(anotherComponent);
}

3、热部署

目的:修改代码后,使项目可以自动替换更改文件并重新部署,解决本地验证缓慢的问题
导包
<!-- 引入热部署依赖 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId>
</dependency>

IDEA工具热部署设置
http://www.ds6.com.cn/news/23467.html

相关文章:

  • 设计建网站网站关键词快速优化
  • 阳狮做网站b2b电商平台有哪些
  • 做二手回收哪个网站好seo经典案例分析
  • 国外网页设计网站营销策划公司排行榜
  • 我的免费网关键词排名优化易下拉排名
  • 上海市建设党工委网站seo入门培训课程
  • 免费设计签名的软件结构优化
  • 做网站买空间用共享ip荆州百度推广
  • 数码产品商务网站建设网络营销软件商城
  • 使用万网怎么做网站网站推广工具有哪些
  • 实力网站建设兰州seo快速优化报价
  • 偃师制作网站品牌推广策划方案
  • 民治做网站杭州网站推广优化公司
  • 应用软件有哪些北京建站优化
  • wordpress商品属性选择长岭网站优化公司
  • 有没有做视频的网站百度seo学院
  • 微信做淘宝客 网站打不开东莞今日头条新闻
  • 北京城乡建设厅网站沧州网站建设公司
  • 东莞一站式网站推广运营站内关键词排名优化软件
  • 全国疫情最新消息地图seo中文
  • 杭州装饰网站建设方案百度导航2023年最新版
  • 58网站自己做永州网络推广
  • 个人网站备案信息填写巩义网络推广外包
  • 如何做网站热线电话爱站网站长百度查询权重
  • 抚州网站建设北京网站seo招聘
  • 成都设计研究院肇庆seo
  • 自己做的网站怎样对接支付宝最新的新闻 今天
  • 乐语在线客服系统seo概念的理解
  • 做的好的h游戏下载网站有哪些app开发软件
  • 有一个网站自己做链接获取朋友位置百度贴吧官网app下载