parent
6129fbdb06
commit
adaf69896e
@ -1,51 +1,46 @@ |
|||||||
package org.pqh.config; |
package org.pqh.config; |
||||||
|
|
||||||
import org.springframework.web.WebApplicationInitializer; |
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 javax.servlet.ServletContext; |
||||||
import java.util.EnumSet; |
import javax.servlet.ServletException; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by reborn on 2017/7/28. |
* 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 { |
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; |
package org.pqh.controller; |
||||||
|
|
||||||
import org.pqh.model.Param; |
import org.pqh.model.Param; |
||||||
import org.pqh.util.DBAction; |
|
||||||
import org.springframework.stereotype.Controller; |
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.RequestMapping; |
||||||
import org.springframework.web.bind.annotation.ResponseBody; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* Created by reborn on 2017/8/3. |
* Created by reborn on 2017/8/3. |
||||||
*/ |
*/ |
||||||
@Controller |
@Controller |
||||||
public class ParamController extends AbstractController<Param> { |
@RequestMapping("/param") |
||||||
@Override |
public class ParamController extends BaseController<Param> { |
||||||
@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); |
|
||||||
} |
|
||||||
} |
} |
||||||
|
@ -1,29 +1,22 @@ |
|||||||
package org.pqh.controller; |
package org.pqh.service; |
||||||
|
|
||||||
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; |
||||||
import org.springframework.dao.DataAccessException; |
import org.springframework.dao.DataAccessException; |
||||||
import org.springframework.stereotype.Controller; |
import org.springframework.stereotype.Service; |
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
|
|
||||||
import javax.annotation.Resource; |
import javax.annotation.Resource; |
||||||
|
|
||||||
/** |
/** |
||||||
* Created by reborn on 2017/7/28. |
* Created by reborn on 2017/7/28. |
||||||
*/ |
*/ |
||||||
@Controller |
@Service |
||||||
public abstract class AbstractController<T extends AbstractModel> { |
public class BaseService<T extends AbstractModel> { |
||||||
|
|
||||||
@Resource |
@Resource |
||||||
private BaseDao baseDao; |
private BaseDao baseDao; |
||||||
|
|
||||||
@RequestMapping("/") |
|
||||||
public String index(){ |
|
||||||
return "index"; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
public String curd(DBAction action,T formModel){ |
public String curd(DBAction action,T formModel){ |
||||||
Class<T> tClass= (Class<T>) formModel.getClass(); |
Class<T> tClass= (Class<T>) formModel.getClass(); |
||||||
try { |
try { |
@ -1,10 +1,10 @@ |
|||||||
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
||||||
<!DOCTYPE html> |
<!DOCTYPE html> |
||||||
<html lang="en"> |
<html lang="en"> |
||||||
<head> |
<head> |
||||||
<meta charset="UTF-8"> |
|
||||||
<title>Title</title> |
<title>Title</title> |
||||||
</head> |
</head> |
||||||
<body> |
<body> |
||||||
<h1>hello world</h1> |
<h1>简单的网络爬虫客户端</h1> |
||||||
</body> |
</body> |
||||||
</html> |
</html> |
Loading…
Reference in new issue