学成在线项目的定义:对各个站点页面的管理,主要管理由于运营而需要经常变动的页面(收费广告轮播图),从而实现根据运营需要快速进行页面开发、上线的需要。
前端静态页面是需要放入NGINX中的,需要在nginx.conf中配置server
SSI包含技术就在这个配置文件中ssi on
#页面预览
upstream cms_server_pool{
server 127.0.0.1:31001 weight=10;
}
server {
listen 80;
#autoindex on;
#在windows开发环境下 有可能会访问的时候是403拒绝(会有目录访问权限)
server_name www.xuecheng.com;
ssi on;
#nginx 开启SSI包含技术
ssi_silent_errors on;
#charset koi8-r;
#access_log logs/host.access.log main;
#门户
location / {
#root html;
#如果是一个目录 最后一定要加/ 否则到时候访问会出现404的问题
alias D:/staticPage/xc-ui-pc-static-portal/;
index index.html index.htm;
#allow all;
}
#页面预览
location /cms/preview/ {
proxy_pass http://cms_server_pool/cms/preview/;
}
}
配置域名访问地址 C:\Windows\System32\drivers\etc\hosts文件
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 www.xuecheng.com
定义 :服务器端嵌入
原理 :在页面还没有到达浏览器的时候,通过一些指令,将多个也没面拼凑到一个页面中。
格式
<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.0modelVersion>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.0.1.RELEASEversion>
parent>
<groupId>com.xuechenggroupId>
<artifactId>xc-framework-parentartifactId>
<packaging>pompackaging>
<version>1.0-SNAPSHOTversion>
<properties>
<java.version>1.8java.version>
<tomcat.version>8.5.28tomcat.version>
<spring-boot.version>2.0.1.RELEASEspring-boot.version>
<springframework.version>5.0.5.RELEASEspringframework.version>
<mybatis-spring-boot.version>1.3.1mybatis-spring-boot.version>
<mybatis.version>3.4.5mybatis.version>
<druid.version>1.1.6druid.version>
<mysql-connector-java.version>5.1.45mysql-connector-java.version>
<commons-io.version>2.6commons-io.version>
<org.apache.commons.io.version>1.3.2org.apache.commons.io.version>
<commons-fileupload.version>1.3.3commons-fileupload.version>
<commons-codec.version>1.10commons-codec.version>
<commons-lang3.version>3.6commons-lang3.version>
<okhttp.version>3.9.1okhttp.version>
<feign-okhttp.version>8.18.0feign-okhttp.version>
<lombok.version>1.16.16lombok.version>
<springfox-swagger.version>2.7.0springfox-swagger.version>
<fastjson.version>1.2.30fastjson.version>
<fastdfs-client-java.version>1.27.0.0fastdfs-client-java.version>
<mysql-connector-java.version>5.1.40mysql-connector-java.version>
<elasticsearch.version>6.2.1elasticsearch.version>
<guava.version>24.0-jreguava.version>
properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-dependenciesartifactId>
<version>Finchley.SR1version>
<type>pomtype>
<scope>importscope>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>${mysql-connector-java.version}version>
dependency>
<dependency>
<groupId>org.mybatis.spring.bootgroupId>
<artifactId>mybatis-spring-boot-starterartifactId>
<version>${mybatis-spring-boot.version}version>
dependency>
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelper-spring-boot-starterartifactId>
<version>1.2.4version>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druidartifactId>
<version>${druid.version}version>
dependency>
<dependency>
<groupId>com.squareup.okhttp3groupId>
<artifactId>okhttpartifactId>
<version>${okhttp.version}version>
dependency>
<dependency>
<groupId>com.netflix.feigngroupId>
<artifactId>feign-okhttpartifactId>
<version>${feign-okhttp.version}version>
dependency>
<dependency>
<groupId>commons-iogroupId>
<artifactId>commons-ioartifactId>
<version>${commons-io.version}version>
dependency>
<dependency>
<groupId>org.apache.commonsgroupId>
<artifactId>commons-ioartifactId>
<version>${org.apache.commons.io.version}version>
dependency>
<dependency>
<groupId>commons-fileuploadgroupId>
<artifactId>commons-fileuploadartifactId>
<version>${commons-fileupload.version}version>
dependency>
<dependency>
<groupId>commons-codecgroupId>
<artifactId>commons-codecartifactId>
<version>${commons-codec.version}version>
dependency>
<dependency>
<groupId>org.apache.commonsgroupId>
<artifactId>commons-lang3artifactId>
<version>${commons-lang3.version}version>
dependency>
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
<version>${lombok.version}version>
dependency>
<dependency>
<groupId>io.springfoxgroupId>
<artifactId>springfox-swagger2artifactId>
<version>${springfox-swagger.version}version>
dependency>
<dependency>
<groupId>io.springfoxgroupId>
<artifactId>springfox-swagger-uiartifactId>
<version>${springfox-swagger.version}version>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>fastjsonartifactId>
<version>${fastjson.version}version>
dependency>
<dependency>
<groupId>net.oschina.zcx7878groupId>
<artifactId>fastdfs-client-javaartifactId>
<version>${fastdfs-client-java.version}version>
dependency>
<dependency>
<groupId>org.elasticsearch.clientgroupId>
<artifactId>elasticsearch-rest-high-level-clientartifactId>
<version>${elasticsearch.version}version>
dependency>
<dependency>
<groupId>org.elasticsearchgroupId>
<artifactId>elasticsearchartifactId>
<version>${elasticsearch.version}version>
dependency>
<dependency>
<groupId>com.google.guavagroupId>
<artifactId>guavaartifactId>
<version>${guava.version}version>
dependency>
dependencies>
dependencyManagement>
<build>
<finalName>${project.artifactId}finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
<configuration>
<source>1.8source>
<target>1.8target>
<encoding>UTF-8encoding>
configuration>
plugin>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
project>
SQL术语/概念 | Mongodb属于/概念 | 解释/说明 |
---|---|---|
database | database | 数据库 |
table | collection | 数据库表、集合 |
row | document | 数据记录行/文档 |
Column | field | 数据字段/域 |
index | index | 索引 |
table join | 不支持连接 | 表连接 |
primary key | primary key | 主键/MongoDB中自动添加一个主键ID |
操作 | 语法 |
---|---|
查询数据库 | show dbs |
创建数据库 | user 任意名称 |
删除当前数据库 | db.dropDatabase() |
创建集合(名字,参数) | db.createCollection(name,option) |
删除集合 | db.collection.drop() |
操作 | 语法 |
---|---|
插入文档 | db.COLLECTION_NAME.insert(json格式数据) |
更新文档 | db.COLLECTION_NAEM.update(查询条件json,更新全部内容json) |
$set修改器修改 | db.COLLECTION_NAME.update({key:value},{$set:{key:value,key:value}},{multi:ture}) |
删除文档 | db.COLLECTION_NAME.remove({条件json}) |
查询全部文档 | db.COLLECTION_NAME.find() |
条件查询 | db.COLLECTION_NAME.find({json格式条件}) |
投影查询 | db.COLLECTION_NAME.find({json条件},{“name”:1,_id:0})----显示name,不显示id |
创建用户
删除用户
db.dropUser("用户名”)
修改用户
db.updateUser(“用户名”,{[role:"readWriteAnyDatebase,db:“admin”]})
认证启动mongo.exe -u root -p 123 --authenticationDatabase admin
配置验证 mongo.conf
在文件中添加 auth=ture
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-data-mongodbartifactId>
dependency>
{
操作是否成功;-,
操作代码:-,
提示信息: -,
lsit: 数据集合,
总记录数
}
创建springboot工程 基于注解开发 继承父工程
spring boot starter web 进行web开发
spring boot starter free mark 模板页面
spring boot starter data mogondb
spring boot starter amqp 消息队列
spring boot starter test 单元测试
补充包结构
config
controller
service
dao
ManageCmsApplication.class(注解启动类,扫描所在包下所有注解)
@SpringBootApplication
@EntityScan("com.xuecheng.framework.domain.cms")//扫描实体类
@ComponentScan(basePackages={"com.xuecheng.cms.api"})//扫描接口
@ComponentScan(basePackages={"com.xuecheng.cms"})//扫描本项目下的所有类
public class ManageCmsApplication {
public static void main(String[] args) {
SpringApplication.run(ManageCmsApplication.class,args);
}
}
server:
port: 31001
spring:
application:
name: xc-service-manage-cms
data:
mongodb:
uri: mongodb://root:123@localhost:27017
database: xc_cms
@RestController
@RequestMapping("/cms/page")
public class CmsPageController implements CmsPageControllerApi {
@Autowired
PageService pageService;
@Override
@GetMapping("/list/{page}/{size}")
public QueryResponseResult findList(@PathVariable("page") int page, @PathVariable("size")int size, QueryPageRequest queryPageRequest) {
//暂时用静态数据
//定义queryResult
QueryResult<CmsPage> queryResult =new QueryResult<>();
List<CmsPage> list = new ArrayList<>();
CmsPage cmsPage = new CmsPage();
cmsPage.setPageName("测试页面");
list.add(cmsPage);
queryResult.setList(list);
queryResult.setTotal(1);
QueryResponseResult queryResponseResult = new QueryResponseResult(CommonCode.SUCCESS,queryResult);
return queryResponseResult;*/
//调用service
// return pageService.findList(page,size,queryPageRequest);
}
public interface CmsPageRepository extends MongoRepository<CmsPage,String> {
//根据页面名称查询
CmsPage findByPageName(String pageName);
//根据页面名称、站点Id、页面webpath查询
CmsPage findByPageNameAndSiteIdAndPageWebPath(String pageName,String siteId,String pageWebPath);
int countBySiteIdAndPageType(String siteId,String pageType);
//分页查询
Page<CmsPage> findSiteIdAndPageType(String siteId,String pageType,Pageable pageable);
}
@SpringBootTest
@RunWith(SpringRunner.class)
public class test {
@Autowired
CmsPageRepository cmsPageRepository;
@Test
public void testFindAll(){
List<CmsPage> all = cmsPageRepository.findAll();
System.out.println(all);
}
//分页查询
@Test
public void testFindPage(){
//分页参数
int size=10;
int page=1;
Pageable pageable = PageRequest.of(page, size);
Page<CmsPage> all = cmsPageRepository.findAll(pageable);
System.out.println(all);
}
}
@Service
public class PageService {
@Autowired
CmsPageRepository cmsPageRepository;
/**
* 页面查询方法
* @param page 页码,从1开始记数
* @param size 每页记录数
* @param queryPageRequest 查询条件
* @return
*/
public QueryResponseResult findList(int page, int size, QueryPageRequest queryPageRequest){
if(queryPageRequest == null){
queryPageRequest = new QueryPageRequest();
}
//自定义条件查询
//定义条件匹配器
ExampleMatcher exampleMatcher = ExampleMatcher.matching()
.withMatcher("pageAliase", ExampleMatcher.GenericPropertyMatchers.contains());
//条件值对象
CmsPage cmsPage = new CmsPage();
//设置条件值(站点id)
if(StringUtils.isNotEmpty(queryPageRequest.getSiteId())){
cmsPage.setSiteId(queryPageRequest.getSiteId());
}
//设置模板id作为查询条件
if(StringUtils.isNotEmpty(queryPageRequest.getTemplateId())){
cmsPage.setTemplateId(queryPageRequest.getTemplateId());
}
//设置页面别名作为查询条件
if(StringUtils.isNotEmpty(queryPageRequest.getPageAliase())){
cmsPage.setPageAliase(queryPageRequest.getPageAliase());
}
//定义条件对象Example
Example<CmsPage> example = Example.of(cmsPage,exampleMatcher);
//分页参数
if(page <=0){
page = 1;
}
page = page -1;
if(size<=0){
size = 10;
}
Pageable pageable = PageRequest.of(page,size);
Page<CmsPage> all = cmsPageRepository.findAll(example,pageable);//实现自定义条件查询并且分页查询
QueryResult queryResult = new QueryResult();
queryResult.setList(all.getContent());//数据列表
queryResult.setTotal(all.getTotalElements());//数据总记录数
QueryResponseResult queryResponseResult = new QueryResponseResult(CommonCode.SUCCESS,queryResult);
return queryResponseResult;
}