Skip to content

Commit

Permalink
整体更改提交
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwujing committed Apr 19, 2018
1 parent 02bd415 commit a4a200a
Show file tree
Hide file tree
Showing 43 changed files with 7,318 additions and 310 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Wed Apr 04 08:29:04 CST 2018
#Thu Apr 19 08:46:52 CST 2018
version=0.0.1-SNAPSHOT
groupId=1.0.0
m2e.projectName=springboot-hello
Expand Down
1 change: 1 addition & 0 deletions springboot-mutilDatasource/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean delete(@RequestBody Student student) {
}

@RequestMapping(value = "/student", method = RequestMethod.GET)
public Student findByStudentName(Student student) {
public Student findByStudent(Student student) {
System.out.println("开始查询...");
return service.findByEntity(student);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Thu Apr 19 11:54:59 CST 2018
#Thu Apr 19 14:33:37 CST 2018
version=0.0.1-SNAPSHOT
groupId=1.0.0
m2e.projectName=springboot-mutilDatasource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -29,13 +30,13 @@ public class UserRestController {
private UserService userService;

@RequestMapping(value = "/user", method = RequestMethod.POST)
public boolean addUser(User user) {
public boolean addUser(@RequestBody User user) {
System.out.println("开始新增...");
return userService.addUser(user);
}

@RequestMapping(value = "/user", method = RequestMethod.PUT)
public boolean updateUser(User user) {
public boolean updateUser(@RequestBody User user) {
System.out.println("开始更新...");
return userService.updateUser(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public static void main(String[] args) {

@Override
public void run(String... strings) throws Exception {
System.out.println("启动一个方法");
System.out.println("启动一个方法测试...");
}
}
60 changes: 46 additions & 14 deletions springboot-summarizing/src/main/java/com/pancm/dao/BaseDao.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
package com.pancm.dao;

import java.util.List;

/**
*
* @Title: BaseDao
* @Description:
* 基础数据层
* @Version:1.0.0
* @author pancm
* @date 2018年4月12日
*/
public interface BaseDao<T> {
/**
* 插入数据
*
* 单条新增插入数据
* @param entity
* @return
* @throws Exception
* @throws
*/
public int insert(T entity) throws Exception;
void insert(T entity) throws Exception;


/**
* 批量新增据插入数据
* @param entityList
* @return
* @throws Exception
* @throws
*/
int insertBatch(List<T> entityList) throws Exception;

/**
* 更新数据
Expand All @@ -19,25 +39,24 @@ public interface BaseDao<T> {
* @throws Exception
* @throws
*/
public int updateByPrimaryKey(T entity) throws Exception;
void update(T entity) throws Exception;

/**
* 删除数据
*
* 根据ID删除数据
* @param id
* @throws Exception
* @throws
*/
public int deleteByPrimaryKey(int id) throws Exception;
void deleteByPrimaryKey(int id) throws Exception;

/**
* 删除数据
*
* @param entity
* @throws Exception
* @throws
*/
public int delete(T entity) throws Exception;
void delete(T entity) throws Exception;


/**
* 根据id查询单个记录
Expand All @@ -47,7 +66,7 @@ public interface BaseDao<T> {
* @throws Exception
* @throws
*/
public T selectByPrimaryKey(int id);
T findByPrimaryKey(int id);

/**
* 根据对象查询单个记录
Expand All @@ -57,8 +76,23 @@ public interface BaseDao<T> {
* @throws Exception
* @throws
*/
public T getOne(T entity);
T findByEntity(T entity);



/**
* 根据对象查询多条记录
* @param entity
* @return
*/
List<T> findByListEntity(T entity);

/**
* 查询所有记录
* @return
*/
List<T> findAll();

/**
* 根据对象查询信息
*
Expand All @@ -67,9 +101,7 @@ public interface BaseDao<T> {
* @throws Exception
* @throws
*/
public Object getObject(Object obj);


Object findByObject(Object obj);



Expand Down
39 changes: 1 addition & 38 deletions springboot-summarizing/src/main/java/com/pancm/dao/UserDao.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.pancm.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

import com.pancm.pojo.User;
Expand All @@ -16,42 +14,7 @@
* @date 2018年1月9日
*/
@Mapper
public interface UserDao {
public interface UserDao extends BaseDao<User>{

/**
* 用户数据新增
*/
void addUser(User user);

/**
* 用户数据修改
*/
void updateUser(User user);

/**
* 用户数据删除
*/
void deleteUser(int id);

/**
* 通过名称查询
* @param name
* @return
*/
User findUserByName(String name);


/**
* 根据用户输入的信息查询
*
*/
User find(User user);



/**
* 查询所有用户信息
*/
List<User> findAll();

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public FilterRegistrationBean testFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new MyFilter());
//过滤掉 /api 和hello 的所有请求
registration.addUrlPatterns("/api/*","/hello");
registration.addUrlPatterns("/*");
registration.addInitParameter("paramName", "paramValue");
registration.setName("MyFilter");
registration.setOrder(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package com.pancm.interceptor;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.pancm.config.IpConfig;
import com.pancm.util.MyTools;


/**
Expand Down Expand Up @@ -48,50 +41,21 @@ public void addInterceptors(InterceptorRegistry registry) {

class MyInterceptor implements HandlerInterceptor {

@Autowired
private IpConfig ipconfig;

/**
* 在请求处理之前进行调用(Controller方法调用之前)调用,
* 返回true 则放行, false 则将直接跳出方法
*/
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
String ip = getIpAddr(request);
String token=request.getParameter("token");
if (!ip.isEmpty()) {
System.out.println("该IP: " + ip+"通过!");
if (MyTools.isEmpty(token)) {
System.out.println("通过!");
return true;
} else {
System.out.println("该IP: " + ip+"不通过!");
System.out.println("不通过!");
return false;
}
}

/**
* 获取访问的ip地址
*
* @param request
* @return
*/
public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}

//请求处理之后进行调用,但是在视图被渲染之前(Controller方法调用之后)
@Override
Expand Down
Loading

0 comments on commit a4a200a

Please sign in to comment.