master
无限超频 7 years ago committed by luffy9412
parent 6129fbdb06
commit adaf69896e
  1. 30
      pom.xml
  2. 15
      src/main/java/org/pqh/config/SpringConfig.java
  3. 65
      src/main/java/org/pqh/config/WebConfig.java
  4. 15
      src/main/java/org/pqh/controller/AdminController.java
  5. 29
      src/main/java/org/pqh/controller/BaseController.java
  6. 14
      src/main/java/org/pqh/controller/ConfigController.java
  7. 14
      src/main/java/org/pqh/controller/ParamController.java
  8. 15
      src/main/java/org/pqh/service/BaseService.java
  9. 4
      src/main/webapp/WEB-INF/jsp/index.jsp

@ -22,33 +22,21 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>LATEST</version>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>LATEST</version>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>LATEST</version>
<version>RELEASE</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework</groupId>-->
<!--<artifactId>spring-test</artifactId>-->
<!--<version>LATEST</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>junit</groupId>-->
<!--<artifactId>junit</artifactId>-->
<!--<version>LATEST</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
@ -57,7 +45,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>LATEST</version>
<version>5.2.10.Final</version>
</dependency>
<dependency>
@ -96,11 +84,11 @@
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>LATEST</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.fusesource.jansi</groupId>-->
<!--<artifactId>jansi</artifactId>-->
<!--<version>LATEST</version>-->
<!--</dependency>-->
<dependency>
<groupId>commons-io</groupId>

@ -1,7 +1,9 @@
package org.pqh.config;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
/**
@ -12,8 +14,19 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
@ComponentScan(basePackages = "org.pqh")
@EnableAspectJAutoProxy
@Import(HibernateConfig.class)
public class SpringConfig{
public class SpringConfig extends WebMvcConfigurationSupport{
private static ApplicationContext applicationContext;
public static <T>T getBean(Class<T> c){
return applicationContext.getBean(c);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
super.setApplicationContext(applicationContext);
SpringConfig.applicationContext=applicationContext;
}
@Bean("viewReslover")
public InternalResourceViewResolver internalResourceViewResolver(){

@ -1,51 +1,46 @@
package org.pqh.config;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.*;
import java.util.EnumSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
/**
* Created by reborn on 2017/7/28.
*/
public class WebConfig implements WebApplicationInitializer {
private String suffix="*.miku";
private String fileEncoding="UTF-8";
public class WebConfig implements WebApplicationInitializer {
private String encoding ="UTF-8";
// @Override
// protected Filter[] getServletFilters() {
// org.springframework.web.SpringServletContainerInitializer
// org.springframework.web.SpringServletContainerInitializer
// return new Filter[]{new CharacterEncodingFilter(encoding)};
// }
//
// @Override
// protected String[] getServletMappings() {
// return new String[]{"/"};
// }
//
// @Override
// protected Class<?>[] getRootConfigClasses() {
// return new Class[0];
// }
//
// @Override
// protected Class<?>[] getServletConfigClasses() {
// return new Class[]{SpringConfig.class};
// }
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
//基于注解配置的上下文
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
//注册Spring容器配置类
context.register(SpringConfig.class);
ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
//配置映射路径
servletContext.log("DispatcherServlet配置映射路径匹配规则:"+suffix);
servlet.addMapping("/",suffix);
//启动顺序
servlet.setLoadOnStartup(1);
servletContext.addListener(new ContextLoaderListener(context));
FilterRegistration.Dynamic characterEncodingFilter=servletContext.addFilter("CharacterEncodingFilter", CharacterEncodingFilter.class);
servletContext.log("CharacterEncodingFilter设置编码:"+fileEncoding);
characterEncodingFilter.setInitParameter("encoding",fileEncoding);
characterEncodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
// FilterRegistration.Dynamic openSessionInViewFilter=servletContext.addFilter("OpenSessionInViewFilter", OpenSessionInViewFilter.class);
// openSessionInViewFilter.setInitParameter("flushMode","AUTO");
// openSessionInViewFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST),true,"/*");
}
}

@ -0,0 +1,15 @@
package org.pqh.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* Created by reborn on 2017/9/14.
*/
@Controller
public class AdminController {
@RequestMapping({"","index"})
private String index(){
return "index";
}
}

@ -0,0 +1,29 @@
package org.pqh.controller;
import org.pqh.model.AbstractModel;
import org.pqh.service.BaseService;
import org.pqh.util.DBAction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
* Created by reborn on 2017/9/14.
*/
@Controller
public class BaseController<T extends AbstractModel> {
@Resource
BaseService<T> baseService;
@ResponseBody
@RequestMapping(value = "{action}",produces = "text/html;charset=UTF-8")
public String curd(@PathVariable DBAction action,T model) {
return baseService.curd(action, model);
}
}

@ -0,0 +1,14 @@
package org.pqh.controller;
import org.pqh.model.Config;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* Created by reborn on 2017/9/14.
*/
@Controller
@RequestMapping("/config")
public class ConfigController extends BaseController<Config> {
}

@ -1,22 +1,14 @@
package org.pqh.controller;
import org.pqh.model.Param;
import org.pqh.util.DBAction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by reborn on 2017/8/3.
*/
@Controller
public class ParamController extends AbstractController<Param> {
@Override
@ResponseBody
@RequestMapping(value = "/param/{action}",produces = "text/html;charset=UTF-8")
public String curd(@PathVariable DBAction action,@ModelAttribute Param formModel) {
return super.curd(action, formModel);
}
@RequestMapping("/param")
public class ParamController extends BaseController<Param> {
}

@ -1,29 +1,22 @@
package org.pqh.controller;
package org.pqh.service;
import org.pqh.dao.BaseDao;
import org.pqh.model.AbstractModel;
import org.pqh.util.DBAction;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* Created by reborn on 2017/7/28.
*/
@Controller
public abstract class AbstractController<T extends AbstractModel> {
@Service
public class BaseService<T extends AbstractModel> {
@Resource
private BaseDao baseDao;
@RequestMapping("/")
public String index(){
return "index";
}
public String curd(DBAction action,T formModel){
Class<T> tClass= (Class<T>) formModel.getClass();
try {

@ -1,10 +1,10 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>hello world</h1>
<h1>简单的网络爬虫客户端</h1>
</body>
</html>
Loading…
Cancel
Save