master
luffy9412 7 years ago
parent c272768c91
commit 400337a86e
  1. 57
      makeGif/pom.xml
  2. 15
      pom.xml
  3. 9
      src/main/java/org/pqh/config/AbstractWebConfig.java
  4. 36
      src/main/java/org/pqh/config/WebConfigImpl.java
  5. 2
      src/main/java/org/pqh/controller/AdminController.java
  6. 7
      src/main/java/org/pqh/controller/BaseController.java
  7. 2
      src/main/java/org/pqh/model/AbstractModel.java
  8. 5
      src/main/java/org/pqh/model/Config.java
  9. 5
      src/main/java/org/pqh/model/Param.java
  10. 6
      src/main/java/org/pqh/service/BaseService.java
  11. 8
      src/main/java/org/pqh/util/Log4jUtil.java
  12. 2
      src/main/webapp/WEB-INF/jsp/index.jsp
  13. 7
      src/test/java/JunitTest.java

@ -0,0 +1,57 @@
<?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">
<parent>
<artifactId>webCrawler</artifactId>
<groupId>org.pqh</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>makeGif</artifactId>
<build>
<finalName>makeGif</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass></mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -5,17 +5,20 @@
<groupId>org.pqh</groupId> <groupId>org.pqh</groupId>
<artifactId>webCrawler</artifactId> <artifactId>webCrawler</artifactId>
<packaging>war</packaging> <packaging>pom</packaging>
<version>1.0</version> <version>1.0</version>
<description>简单的网络爬虫客户端</description> <description>简单的网络爬虫客户端</description>
<modules>
<module>makeGif</module>
</modules>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<mysql.version>6.0.6</mysql.version> <mysql.version>6.0.6</mysql.version>
<spring.version>4.3.8.RELEASE</spring.version> <spring.version>RELEASE</spring.version>
</properties> </properties>
<dependencies> <dependencies>
@ -46,7 +49,7 @@
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId> <artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version> <version>RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
@ -104,6 +107,11 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!--<dependency>-->
<!--<groupId>org.pqh</groupId>-->
<!--<artifactId>makeGif</artifactId>-->
<!---->
<!--</dependency>-->
</dependencies> </dependencies>
<build> <build>
@ -125,4 +133,5 @@
</build> </build>
</project> </project>

@ -1,16 +1,20 @@
package org.pqh.config; package org.pqh.config;
import org.apache.logging.log4j.LogManager;
import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import javax.servlet.*; import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.EnumSet; import java.util.EnumSet;
/** /**
* Created by reborn on 2017/7/28. * Created by reborn on 2017/7/28.
*/ */
public class WebConfig extends AbstractAnnotationConfigDispatcherServletInitializer { public class AbstractWebConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
private String encoding ="UTF-8"; private String encoding ="UTF-8";
@ -31,6 +35,7 @@ public class WebConfig extends AbstractAnnotationConfigDispatcherServletInitiali
@Override @Override
public void onStartup(ServletContext servletContext) throws ServletException { public void onStartup(ServletContext servletContext) throws ServletException {
LogManager.getLogger().info("onStartup");
super.onStartup(servletContext); super.onStartup(servletContext);
FilterRegistration.Dynamic dynamic=super.registerServletFilter(servletContext,new CharacterEncodingFilter(encoding)); FilterRegistration.Dynamic dynamic=super.registerServletFilter(servletContext,new CharacterEncodingFilter(encoding));
dynamic.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*"); dynamic.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");

@ -0,0 +1,36 @@
package org.pqh.config;
import org.apache.logging.log4j.LogManager;
import org.springframework.web.WebApplicationInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
/**
* Created by reborn on 2017/9/18.
*/
public class WebConfigImpl implements WebApplicationInitializer{
private String encoding ="UTF-8";
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
LogManager.getLogger().info("onStartup");
// //基于注解配置的上下文
// AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
// //注册Spring容器配置类
// context.register(SpringConfig.class);
// ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
// //配置映射路径
// servlet.addMapping("/");
// //启动顺序
// servlet.setLoadOnStartup(1);
//
//
// servletContext.addListener(new ContextLoaderListener(context));
//
// FilterRegistration.Dynamic characterEncodingFilter=servletContext.addFilter("CharacterEncodingFilter", CharacterEncodingFilter.class);
// servletContext.log("CharacterEncodingFilter设置编码:"+encoding);
// characterEncodingFilter.setInitParameter("encoding",encoding);
// characterEncodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
}
}

@ -1,5 +1,6 @@
package org.pqh.controller; package org.pqh.controller;
import org.apache.logging.log4j.LogManager;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class AdminController{ public class AdminController{
@RequestMapping({"","index"}) @RequestMapping({"","index"})
private String index(){ private String index(){
LogManager.getLogger().info("进入首页");
return "index"; return "index";
} }
} }

@ -1,5 +1,7 @@
package org.pqh.controller; package org.pqh.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.pqh.model.AbstractModel; import org.pqh.model.AbstractModel;
import org.pqh.service.BaseService; import org.pqh.service.BaseService;
import org.pqh.util.DBAction; import org.pqh.util.DBAction;
@ -16,12 +18,15 @@ import javax.annotation.Resource;
@Controller @Controller
public class BaseController<T extends AbstractModel> { public class BaseController<T extends AbstractModel> {
protected Logger log= LogManager.getLogger();
@Resource @Resource
BaseService<T> baseService; protected BaseService<T> baseService;
@ResponseBody @ResponseBody
@RequestMapping(value = "{action}",produces = "text/html;charset=UTF-8") @RequestMapping(value = "{action}",produces = "text/html;charset=UTF-8")
public String curd(@PathVariable DBAction action,T model) { public String curd(@PathVariable DBAction action,T model) {
log.info(model.tableNote()+"进行"+action+"操作请求");
return baseService.curd(action, model); return baseService.curd(action, model);
} }

@ -8,4 +8,6 @@ import java.io.Serializable;
public abstract class AbstractModel { public abstract class AbstractModel {
public abstract Serializable primaryKey(); public abstract Serializable primaryKey();
public abstract String tableNote();
} }

@ -44,4 +44,9 @@ public class Config extends AbstractModel{
public Serializable primaryKey() { public Serializable primaryKey() {
return getJackson(); return getJackson();
} }
@Override
public String tableNote() {
return "测试表";
}
} }

@ -80,4 +80,9 @@ public class Param extends AbstractModel{
public Serializable primaryKey() { public Serializable primaryKey() {
return getKey(); return getKey();
} }
@Override
public String tableNote() {
return "系统参数表";
}
} }

@ -1,5 +1,7 @@
package org.pqh.service; package org.pqh.service;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.pqh.dao.BaseDao; import org.pqh.dao.BaseDao;
import org.pqh.model.AbstractModel; import org.pqh.model.AbstractModel;
import org.pqh.util.DBAction; import org.pqh.util.DBAction;
@ -14,6 +16,8 @@ import javax.annotation.Resource;
@Service @Service
public class BaseService<T extends AbstractModel> { public class BaseService<T extends AbstractModel> {
protected Logger log= LogManager.getLogger();
@Resource @Resource
private BaseDao baseDao; private BaseDao baseDao;
@ -34,7 +38,7 @@ public class BaseService<T extends AbstractModel> {
} }
return action+" success"; return action+" success";
}catch (DataAccessException e){ }catch (DataAccessException e){
log.error(formModel.tableNote()+"进行"+action+"操作失败,原因是:"+e.getMessage());
} }
return action+" fail"; return action+" fail";
} }

@ -1,8 +0,0 @@
package org.pqh.util;
/**
* Created by reborn on 2017/8/8.
*/
public class Log4jUtil {
}

@ -5,6 +5,6 @@
<title>Title</title> <title>Title</title>
</head> </head>
<body> <body>
<h1>简单的网络爬虫客户端</h1> <h1>首页</h1>
</body> </body>
</html> </html>

@ -2,7 +2,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.xml.XmlConfiguration; import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
import org.pqh.util.Log4jUtil;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -24,11 +23,6 @@ public class JunitTest {
// consoleLogger.info("consoleLogger"); // consoleLogger.info("consoleLogger");
// loggerFile.info("loggerFile"); // loggerFile.info("loggerFile");
LogManager.getLogger("test1").info("test1");
LogManager.getLogger("test2").info("test2");
LogManager.getLogger("test3").info("test3");
LogManager.getLogger().info("test4");
// Collection<org.apache.logging.log4j.core.Logger> loggers=loggerContext.getLoggers(); // Collection<org.apache.logging.log4j.core.Logger> loggers=loggerContext.getLoggers();
// for(org.apache.logging.log4j.core.Logger logger:loggers){ // for(org.apache.logging.log4j.core.Logger logger:loggers){
// logger.info(logger.getName()); // logger.info(logger.getName());
@ -40,7 +34,6 @@ public class JunitTest {
private static boolean init(){ private static boolean init(){
System.out.println(Log4jUtil.class.getClassLoader());
System.out.println(XmlConfiguration.class.getClassLoader()); System.out.println(XmlConfiguration.class.getClassLoader());
LoggerContext loggerContext= (LoggerContext) LogManager.getContext(false); LoggerContext loggerContext= (LoggerContext) LogManager.getContext(false);
try { try {

Loading…
Cancel
Save