├── .gitignore ├── doc ├── ~$学生选课系统.docx └── 高校学生选课系统.docx ├── logs └── mylog-2017-03-03.0.log ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── hus │ │ ├── Application.java │ │ ├── common │ │ ├── config │ │ │ ├── DruidConfiguration.java │ │ │ ├── MelodyConfiguration.java │ │ │ ├── MybaitsConfig.java │ │ │ ├── TransactionConfig.java │ │ │ └── WebConfiguration.java │ │ ├── consts │ │ │ ├── App.java │ │ │ ├── Url.java │ │ │ └── View.java │ │ ├── swagger │ │ │ └── Swagger2.java │ │ └── utils │ │ │ └── MyX509TrustManagerUtil.java │ │ └── web │ │ ├── controller │ │ ├── api │ │ │ └── ApiController.java │ │ ├── web │ │ │ ├── BaseConrtoller.java │ │ │ ├── CourseController.java │ │ │ ├── DemoController.java │ │ │ ├── LoginController.java │ │ │ └── UserController.java │ │ └── wechat │ │ │ ├── WechatAuthController.java │ │ │ └── WechatEventController.java │ │ ├── entity │ │ ├── Course.java │ │ ├── SystemModule.java │ │ └── User.java │ │ ├── mapper │ │ ├── CourseMapper.java │ │ ├── DepartmentMapper.java │ │ ├── SystemModuleMapper.java │ │ └── UserMapper.java │ │ ├── service │ │ ├── CourseService.java │ │ ├── LoginService.java │ │ └── UserService.java │ │ └── utils │ │ ├── HttpClientUtil.java │ │ └── SignUtil.java ├── resources │ ├── config │ │ └── application.yml │ └── sqlMap │ │ ├── CourseMapper.xml │ │ ├── DepartmentMapper.xml │ │ ├── SystemModuleMapper.xml │ │ └── UserMapper.xml └── webapp │ ├── WEB-INF │ ├── view │ │ ├── course │ │ │ ├── admin_index.jsp │ │ │ └── index.jsp │ │ ├── error.jsp │ │ ├── home │ │ │ └── index.jsp │ │ ├── login │ │ │ └── index.jsp │ │ ├── mobile │ │ │ ├── index.jsp │ │ │ └── student_choosed_page.jsp │ │ ├── student │ │ │ ├── choosed_course.jsp │ │ │ └── index.jsp │ │ └── teacher │ │ │ └── index.jsp │ └── web.xml │ ├── base.jsp │ ├── bootstrap │ ├── css │ │ ├── bootstrap-switch.css │ │ ├── bootstrap-switch.min.css │ │ ├── bootstrap-theme.css │ │ ├── bootstrap-theme.css.map │ │ ├── bootstrap-theme.min.css │ │ ├── bootstrap-theme.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ └── js │ │ ├── bootstrap-paginator.js │ │ ├── bootstrap-switch.js │ │ ├── bootstrap-switch.min.js │ │ ├── bootstrap.js │ │ ├── bootstrap.min.js │ │ └── npm.js │ ├── css │ ├── leftMenu.css │ └── signin.css │ ├── js │ └── jquery.min.js │ ├── layui │ ├── css │ │ ├── layui.css │ │ ├── layui.mobile.css │ │ └── modules │ │ │ ├── code.css │ │ │ ├── laydate │ │ │ ├── icon.png │ │ │ └── laydate.css │ │ │ └── layer │ │ │ └── default │ │ │ ├── icon-ext.png │ │ │ ├── icon.png │ │ │ ├── layer.css │ │ │ ├── loading-0.gif │ │ │ ├── loading-1.gif │ │ │ └── loading-2.gif │ ├── font │ │ ├── iconfont.eot │ │ ├── iconfont.svg │ │ ├── iconfont.ttf │ │ └── iconfont.woff │ ├── images │ │ └── face │ │ │ ├── 0.gif │ │ │ ├── 1.gif │ │ │ ├── 10.gif │ │ │ ├── 11.gif │ │ │ ├── 12.gif │ │ │ ├── 13.gif │ │ │ ├── 14.gif │ │ │ ├── 15.gif │ │ │ ├── 16.gif │ │ │ ├── 17.gif │ │ │ ├── 18.gif │ │ │ ├── 19.gif │ │ │ ├── 2.gif │ │ │ ├── 20.gif │ │ │ ├── 21.gif │ │ │ ├── 22.gif │ │ │ ├── 23.gif │ │ │ ├── 24.gif │ │ │ ├── 25.gif │ │ │ ├── 26.gif │ │ │ ├── 27.gif │ │ │ ├── 28.gif │ │ │ ├── 29.gif │ │ │ ├── 3.gif │ │ │ ├── 30.gif │ │ │ ├── 31.gif │ │ │ ├── 32.gif │ │ │ ├── 33.gif │ │ │ ├── 34.gif │ │ │ ├── 35.gif │ │ │ ├── 36.gif │ │ │ ├── 37.gif │ │ │ ├── 38.gif │ │ │ ├── 39.gif │ │ │ ├── 4.gif │ │ │ ├── 40.gif │ │ │ ├── 41.gif │ │ │ ├── 42.gif │ │ │ ├── 43.gif │ │ │ ├── 44.gif │ │ │ ├── 45.gif │ │ │ ├── 46.gif │ │ │ ├── 47.gif │ │ │ ├── 48.gif │ │ │ ├── 49.gif │ │ │ ├── 5.gif │ │ │ ├── 50.gif │ │ │ ├── 51.gif │ │ │ ├── 52.gif │ │ │ ├── 53.gif │ │ │ ├── 54.gif │ │ │ ├── 55.gif │ │ │ ├── 56.gif │ │ │ ├── 57.gif │ │ │ ├── 58.gif │ │ │ ├── 59.gif │ │ │ ├── 6.gif │ │ │ ├── 60.gif │ │ │ ├── 61.gif │ │ │ ├── 62.gif │ │ │ ├── 63.gif │ │ │ ├── 64.gif │ │ │ ├── 65.gif │ │ │ ├── 66.gif │ │ │ ├── 67.gif │ │ │ ├── 68.gif │ │ │ ├── 69.gif │ │ │ ├── 7.gif │ │ │ ├── 70.gif │ │ │ ├── 71.gif │ │ │ ├── 8.gif │ │ │ └── 9.gif │ ├── lay │ │ ├── dest │ │ │ └── layui.all.js │ │ └── modules │ │ │ ├── code.js │ │ │ ├── element.js │ │ │ ├── flow.js │ │ │ ├── form.js │ │ │ ├── jquery.js │ │ │ ├── laydate.js │ │ │ ├── layedit.js │ │ │ ├── layer.js │ │ │ ├── laypage.js │ │ │ ├── laytpl.js │ │ │ ├── mobile.js │ │ │ ├── tree.js │ │ │ ├── upload.js │ │ │ └── util.js │ └── layui.js │ ├── menu.jsp │ └── nav.jsp └── test └── java └── com └── hus └── DemoApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | /log 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /doc/~$学生选课系统.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heavenfucking/SpringBootHus/58ea23de02f0868afdf43879f9e45b2d676df16c/doc/~$学生选课系统.docx -------------------------------------------------------------------------------- /doc/高校学生选课系统.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heavenfucking/SpringBootHus/58ea23de02f0868afdf43879f9e45b2d676df16c/doc/高校学生选课系统.docx -------------------------------------------------------------------------------- /logs/mylog-2017-03-03.0.log: -------------------------------------------------------------------------------- 1 | https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa4cc0a202b65477c&redirect_uri=http://17157bv023.51mypc.cn/hus/wechat/callback&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect 2 | https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa4cc0a202b65477c&redirect_uri=http://17157bv023.51mypc.cn/hus/wechat/callback&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect 3 | { 4 | "button":[ 5 | { 6 | "name":"自助服务", 7 | "sub_button":[ 8 | { 9 | "type":"view", 10 | "name":"高校学生选课系统学生登录", 11 | "url":"http://17157bv023.51mypc.cn/hus/wechat/enter" 12 | }] 13 | }] 14 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | demo 8 | 0.0.1-SNAPSHOT 9 | war 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.1.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | 35 | javax.servlet 36 | javax.servlet-api 37 | 38 | 39 | javax.servlet 40 | jstl 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-tomcat 47 | 48 | 49 | org.apache.tomcat.embed 50 | tomcat-embed-jasper 51 | 52 | 53 | 54 | 55 | mysql 56 | mysql-connector-java 57 | 5.1.39 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-starter-jdbc 63 | 64 | 65 | 66 | com.alibaba 67 | druid 68 | 1.0.26 69 | 70 | 71 | 72 | 73 | org.mybatis 74 | mybatis 75 | 3.4.1 76 | 77 | 78 | org.mybatis 79 | mybatis-spring 80 | 1.3.0 81 | 82 | 83 | 84 | 85 | net.bull.javamelody 86 | javamelody-core 87 | 1.60.0 88 | 89 | 90 | 91 | org.apache.httpcomponents 92 | httpclient 93 | 4.3.4 94 | 95 | 96 | org.apache.httpcomponents 97 | httpasyncclient 98 | 4.0.2 99 | 100 | 101 | commons-httpclient 102 | commons-httpclient 103 | 3.1 104 | 105 | 106 | 107 | io.springfox 108 | springfox-swagger-ui 109 | 2.6.1 110 | 111 | 112 | io.springfox 113 | springfox-swagger2 114 | 2.6.1 115 | 116 | 117 | 118 | commons-lang 119 | commons-lang 120 | 2.6 121 | 122 | 123 | 124 | 125 | net.sf.json-lib 126 | json-lib 127 | 2.4 128 | jdk15 129 | 130 | 131 | 132 | org.springframework.boot 133 | spring-boot-starter-test 134 | test 135 | 136 | 137 | 138 | 139 | demo 140 | 141 | 142 | org.springframework.boot 143 | spring-boot-maven-plugin 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /src/main/java/com/hus/Application.java: -------------------------------------------------------------------------------- 1 | package com.hus; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | public static void main(String[] args) { 9 | SpringApplication.run(Application.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/config/DruidConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.config; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import com.alibaba.druid.support.http.StatViewServlet; 5 | import com.alibaba.druid.support.http.WebStatFilter; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 8 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | import javax.sql.DataSource; 13 | import java.sql.SQLException; 14 | 15 | /** 16 | * Created by zhao on 2017/3/3. 17 | */ 18 | @Configuration 19 | public class DruidConfiguration { 20 | 21 | @Bean 22 | public ServletRegistrationBean druidServlet() { 23 | return new ServletRegistrationBean(new StatViewServlet(), "/druid/*"); 24 | } 25 | 26 | @Bean 27 | public DataSource druidDataSource(@Value("${spring.datasource.driver}") String driver, 28 | @Value("${spring.datasource.url}") String url, 29 | @Value("${spring.datasource.username}") String username, 30 | @Value("${spring.datasource.password}") String password) { 31 | DruidDataSource druidDataSource = new DruidDataSource(); 32 | druidDataSource.setDriverClassName(driver); 33 | druidDataSource.setUrl(url); 34 | druidDataSource.setUsername(username); 35 | druidDataSource.setPassword(password); 36 | try { 37 | druidDataSource.setFilters("stat, wall"); 38 | } catch (SQLException e) { 39 | e.printStackTrace(); 40 | } 41 | return druidDataSource; 42 | } 43 | 44 | @Bean 45 | public FilterRegistrationBean filterRegistrationBean() { 46 | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); 47 | filterRegistrationBean.setFilter(new WebStatFilter()); 48 | filterRegistrationBean.addUrlPatterns("/*"); 49 | filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); 50 | return filterRegistrationBean; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/config/MelodyConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.config; 2 | 3 | import net.bull.javamelody.MonitoringFilter; 4 | import net.bull.javamelody.Parameter; 5 | import net.bull.javamelody.SessionListener; 6 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 7 | import org.springframework.boot.web.servlet.ServletContextInitializer; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.servlet.DispatcherType; 12 | import javax.servlet.ServletContext; 13 | import javax.servlet.ServletException; 14 | 15 | /** 16 | * Created by zhu on 2017/2/21. 17 | */ 18 | @Component 19 | public class MelodyConfiguration implements ServletContextInitializer { 20 | @Override 21 | public void onStartup(ServletContext servletContext) throws ServletException { 22 | 23 | } 24 | @Bean 25 | public FilterRegistrationBean registrationBean() { 26 | FilterRegistrationBean javaMelody = new FilterRegistrationBean(); 27 | javaMelody.setFilter(new MonitoringFilter()); 28 | javaMelody.setAsyncSupported(true); 29 | javaMelody.setName("melody"); 30 | javaMelody.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC); 31 | javaMelody.addInitParameter(Parameter.LOG.getCode(), "true"); 32 | return javaMelody; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/config/MybaitsConfig.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.config; 2 | 3 | import org.mybatis.spring.SqlSessionFactoryBean; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.mybatis.spring.mapper.MapperScannerConfigurer; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 10 | 11 | import javax.sql.DataSource; 12 | import java.io.IOException; 13 | 14 | /** 15 | * Created by zhh on 2017/3/3. 16 | */ 17 | @Configuration 18 | @MapperScan("com.hus.web.mapper") 19 | public class MybaitsConfig { 20 | 21 | @Autowired 22 | private DataSource dataSource; 23 | @Bean(name = "sqlSessionFactory") 24 | public SqlSessionFactoryBean sqlSessionFactory() { 25 | SqlSessionFactoryBean session = new SqlSessionFactoryBean(); 26 | try { 27 | session.setDataSource(dataSource); 28 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 29 | session.setMapperLocations(resolver.getResources("classpath:sqlMap/*.xml")); 30 | } catch (IOException e) { 31 | e.printStackTrace(); 32 | } 33 | return session; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/config/TransactionConfig.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 7 | import org.springframework.transaction.PlatformTransactionManager; 8 | import org.springframework.transaction.annotation.EnableTransactionManagement; 9 | import org.springframework.transaction.annotation.TransactionManagementConfigurer; 10 | 11 | import javax.annotation.Resource; 12 | import javax.sql.DataSource; 13 | 14 | /** 15 | * Created by tanghong on 2017/2/21. 16 | */ 17 | @Configuration 18 | public class TransactionConfig implements TransactionManagementConfigurer { 19 | 20 | 21 | @Resource(name = "transactionManager") 22 | PlatformTransactionManager transactionManager; 23 | 24 | @Bean(name ="transactionManager") 25 | public PlatformTransactionManager getManager(DataSource dataSource){ 26 | return new DataSourceTransactionManager(dataSource); 27 | } 28 | @Override 29 | public PlatformTransactionManager annotationDrivenTransactionManager() { 30 | return transactionManager; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/config/WebConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.config; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.HandlerInterceptor; 7 | import org.springframework.web.servlet.ModelAndView; 8 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 9 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 11 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | /** 17 | * Created by zhh on 2017/3/3. 18 | */ 19 | //@Configuration 20 | //@EnableWebMvc 21 | public class WebConfiguration extends WebMvcConfigurerAdapter { 22 | 23 | @Override 24 | public void addInterceptors(InterceptorRegistry registry) { 25 | // 多个拦截器组成一个拦截器链 26 | // addPathPatterns 用于添加拦截规则 27 | // excludePathPatterns 用户排除拦截 28 | // registry.addInterceptor(new MyInterceptor1()).excludePathPatterns("/**"); 29 | // registry.addInterceptor(new MyInterceptor2()).addPathPatterns("/**"); 30 | super.addInterceptors(registry); 31 | } 32 | 33 | private class MyInterceptor1 extends HandlerInterceptorAdapter{ 34 | private Logger logger = LoggerFactory.getLogger(this.getClass()); 35 | 36 | @Override 37 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 38 | logger.info("remoteAddr="+request.getRemoteAddr()+" request="+request.getRequestURI()); 39 | return true; 40 | } 41 | 42 | @Override 43 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { 44 | super.postHandle(request, response, handler, modelAndView); 45 | } 46 | 47 | } 48 | 49 | private class MyInterceptor2 implements HandlerInterceptor { 50 | 51 | @Override 52 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) 53 | throws Exception { 54 | System.out.println(">>>MyInterceptor2>>>>>>>在请求处理之前进行调用(Controller方法调用之前)"); 55 | 56 | return true;// 只有返回true才会继续向下执行,返回false取消当前请求 57 | } 58 | 59 | @Override 60 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, 61 | ModelAndView modelAndView) throws Exception { 62 | System.out.println(">>>MyInterceptor2>>>>>>>请求处理之后进行调用,但是在视图被渲染之前(Controller方法调用之后)"); 63 | } 64 | 65 | @Override 66 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) 67 | throws Exception { 68 | System.out.println(">>>MyInterceptor2>>>>>>>在整个请求结束之后被调用,也就是在DispatcherServlet 渲染了对应的视图之后执行(主要是用于进行资源清理工作)"); 69 | } 70 | 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/com/hus/common/consts/App.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.consts; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by zhu on 2017/3/15. 8 | */ 9 | public interface App { 10 | 11 | @Component 12 | class Wechat { 13 | /** 微信公众号唯一标识*/ 14 | public static String APPID; 15 | /** 微信公众号的appsecret */ 16 | public static String APPSECRET; 17 | 18 | @Value("${spring.wechat.appID}") 19 | public void setAPPID(String APPID) { 20 | Wechat.APPID = APPID; 21 | } 22 | @Value("${spring.wechat.appsecret}") 23 | public void setAPPSECRET(String APPSECRET) { 24 | Wechat.APPSECRET = APPSECRET; 25 | } 26 | } 27 | 28 | class Session { 29 | /** 当前用户的ACCESS_TOKEN */ 30 | public static final String WECHAT_USER_ACCESS_TOKEN = "session_key_wechat_user_access_token"; 31 | /** 当前用户的openid */ 32 | public static final String WECHAT_USER_OPEN_ID = "session_key_user_open_id"; 33 | /** 当前用户对象 */ 34 | public static final String CURRENT_USER_OBJECT = "session_key_current_user_object"; 35 | /** 系统菜单 */ 36 | public static final String SYSTEM_MENU_ALL = "session_key_system_menu_all"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/consts/Url.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.consts; 2 | 3 | public interface Url { 4 | 5 | /** 微信接口 */ 6 | class Wechat { 7 | /** 微信开发者接口 */ 8 | public static final String CORE_SERVICE = "coreService"; 9 | /** 微信授权回调接口 */ 10 | public static final String CALL_BACK = "wechat/callback"; 11 | /** 获取用户授权access_token的url */ 12 | public static final String AUTH_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code"; 13 | /** 14 | * 菜单创建-微信接口 15 | */ 16 | public static final String CREATE_NORMAL_MENU_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN"; 17 | /** 18 | * 获取accessToken 19 | */ 20 | public static final String GET_ACCESSTOKEN = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" 21 | + "client_credential&appid=APPID&secret=APPSECRET"; 22 | 23 | } 24 | 25 | class Login{ 26 | 27 | public static final String SHOW_LOGIN_PAGE = ""; 28 | 29 | 30 | public static final String USER_LOGIN_URL = "user/login"; 31 | 32 | public static final String WECHAT_USER_LOGIN_URL = "wechatuser/login"; 33 | } 34 | 35 | class Course{ 36 | 37 | public static final String COURSE_LIST_URL = "course/list"; 38 | 39 | public static final String COURSE_ADD_URL = "course/add"; 40 | 41 | public static final String COURSE_UPDATE_URL = "course/update"; 42 | 43 | public static final String COURSE_INFO_URL = "course/info/{id}"; 44 | 45 | public static final String COURSE_DELETE_URL = "course/delete/{id}"; 46 | 47 | public static final String COURSE_LIST_URL_FOR_STU = "course/stulist"; 48 | 49 | public static final String WX_COURSE_LIST_URL_FOR_STU = "wx_course/stulist"; 50 | 51 | public static final String COURSE_LIST_URL_FOR_DDMIN = "course/adminlist"; 52 | } 53 | 54 | class Student{ 55 | 56 | public static final String STUDENt_LIST_URL = "student/list"; 57 | 58 | public static final String STUDENt_ADD_URL = "student/add"; 59 | 60 | public static final String STUDENT_UPDATE_URL = "student/update"; 61 | 62 | public static final String STUDENT_DELETE_URL = "student/delete/{id}"; 63 | 64 | public static final String STUDENT_INFO_URL = "student/info/{id}"; 65 | 66 | public static final String STUDENT_CHOOSED_COURSE = "student/choose/course"; 67 | 68 | public static final String STUDENT_UNCHOOSED_COURSE = "student/unchoose/course"; 69 | } 70 | 71 | class Teacher{ 72 | public static final String TEACHER_LIST_URL = "teacher/list"; 73 | public static final String TEACHER_ADD_URL = "teacher/add"; 74 | public static final String TEACHER_UPDATE_URL = "teacher/update"; 75 | public static final String TEACHER_DELETE_URL = "teacher/delete/{id}"; 76 | public static final String TEACHER_INFO_URL = "teacher/info/{id}"; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/consts/View.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.consts; 2 | 3 | /** 4 | * Created by zhh on 2017/5/4. 5 | */ 6 | public interface View { 7 | 8 | /** 9 | * 首页 10 | */ 11 | class Index{ 12 | 13 | /** 登陆主页 */ 14 | public static final String LOGIN_HOME_PAGE = "home/index"; 15 | 16 | /** WX 登陆主页 */ 17 | public static final String WX_LOGIN_HOME_PAGE = "mobile/index"; 18 | 19 | 20 | /**登录页面 **/ 21 | public static final String LOGIN_PAGE = "login/index"; 22 | } 23 | 24 | class Course{ 25 | 26 | /** 课程课表 */ 27 | public static final String COURSE_LIST_VIEW = "course/index"; 28 | 29 | /** 管理员看到的课程列表 */ 30 | public static final String ADMIN_COURSE_LIST_VIEW = "course/admin_index"; 31 | 32 | 33 | } 34 | 35 | class Student{ 36 | 37 | public static final String STUDENt_LIST_VIEW = "student/index"; 38 | 39 | /** 学生选课时看到的课程列表 */ 40 | public static final String COURSE_LIST_VIEW = "student/choosed_course"; 41 | 42 | /** 微信端 学生选课时看到的课程列表 */ 43 | public static final String COURSE_LIST_VIEW2 = "mobile/student_choosed_page"; 44 | } 45 | 46 | class Teacher{ 47 | 48 | public static final String TEACHER_LIST_VIEW = "teacher/index"; 49 | 50 | } 51 | 52 | class Error { 53 | public static final String ERROR_PAGE_VIEW = "teacher/index"; 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/swagger/Swagger2.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.swagger; 2 | 3 | 4 | import io.swagger.annotations.ApiOperation; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.builders.ResponseMessageBuilder; 11 | import springfox.documentation.schema.ModelRef; 12 | import springfox.documentation.service.ApiInfo; 13 | import springfox.documentation.service.Contact; 14 | import springfox.documentation.spi.DocumentationType; 15 | import springfox.documentation.spring.web.plugins.Docket; 16 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 17 | 18 | import static com.google.common.collect.Lists.newArrayList; 19 | 20 | /** 21 | * Created by zzh on 16/9/12. 22 | */ 23 | @Configuration 24 | @EnableSwagger2 25 | public class Swagger2 { 26 | @Bean 27 | public Docket api() { 28 | return new Docket(DocumentationType.SWAGGER_2) 29 | .select() 30 | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) 31 | .paths(PathSelectors.any()) 32 | .build() 33 | .apiInfo(apiInfo()) 34 | .useDefaultResponseMessages(false) 35 | .globalResponseMessage(RequestMethod.POST, 36 | newArrayList( 37 | new ResponseMessageBuilder() 38 | .code(0) 39 | .message("请求成功,返回结果") 40 | .build(), 41 | new ResponseMessageBuilder() 42 | .code(-1) 43 | .message("系统错误,请提交Bug") 44 | .responseModel(new ModelRef("Error")) 45 | .build() 46 | )); 47 | } 48 | private ApiInfo apiInfo() { 49 | return new ApiInfo( 50 | "标题", 51 | "描述", 52 | "1.0", 53 | "", 54 | new Contact("朱昊", "", ""), 55 | "zhuhao.info", 56 | "zhuhao.info"); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/hus/common/utils/MyX509TrustManagerUtil.java: -------------------------------------------------------------------------------- 1 | package com.hus.common.utils; 2 | 3 | import javax.net.ssl.X509TrustManager; 4 | import java.security.cert.CertificateException; 5 | import java.security.cert.X509Certificate; 6 | 7 | /** 8 | * 证书信任管理器(用于https请求) 9 | */ 10 | public class MyX509TrustManagerUtil implements X509TrustManager { 11 | 12 | /** 13 | * @param chain c 14 | * @param authType t 15 | * @throws CertificateException 异常 16 | */ 17 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 18 | } 19 | 20 | /** 21 | * @param chain c 22 | * @param authType t 23 | * @throws CertificateException 异常 24 | */ 25 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 26 | } 27 | 28 | public X509Certificate[] getAcceptedIssuers() { 29 | return null; 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/com/hus/web/controller/api/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.controller.api; 2 | 3 | import io.swagger.annotations.*; 4 | import org.springframework.http.MediaType; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | /** 8 | * Created by zhh on 2017/3/3. 9 | */ 10 | @Api(value = "hus", description = "测试API", produces = MediaType.APPLICATION_JSON_VALUE) 11 | @RestController 12 | public class ApiController { 13 | @ApiOperation(value = "线上订单列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE) 14 | @ApiResponses(value = {@ApiResponse(code = 0, message = "线上订单列表", response = String.class)}) 15 | @RequestMapping(value = "test/api", method = RequestMethod.POST) 16 | public Object orderListForMall( @ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNo, 17 | @ApiParam("日期类型(-1:全部,0:今天,1:一周内,2:一个月内,3:三个月内,4:半年内,5:一年内)") 18 | @RequestParam(defaultValue = "-1") String dateType, 19 | @ApiParam("订单状态(-1:全部,1:待付款,2:未发货,4:已发货,5:交易完成)") 20 | @RequestParam(defaultValue = "-1") Integer status, 21 | @ApiParam("商品ID") @RequestParam(defaultValue = "-1") String productId, 22 | @ApiParam("门店ID") @RequestParam(defaultValue = "-1") Integer storeId) { 23 | return "success"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/controller/web/BaseConrtoller.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.controller.web; 2 | 3 | import com.hus.common.consts.App; 4 | import com.hus.web.entity.User; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | /** 9 | * Created by zhh on 2017/5/8. 10 | */ 11 | public class BaseConrtoller { 12 | 13 | public Integer getUserId(HttpServletRequest request){ 14 | User user = (User) request.getSession().getAttribute(App.Session.CURRENT_USER_OBJECT); 15 | if(user==null){ 16 | return -1; 17 | } 18 | return user.getId(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/controller/web/CourseController.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.controller.web; 2 | 3 | import com.hus.common.consts.Url; 4 | import com.hus.web.entity.Course; 5 | import com.hus.web.entity.User; 6 | import com.hus.web.mapper.CourseMapper; 7 | import com.hus.web.service.CourseService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Controller; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestMethod; 13 | import org.springframework.web.bind.annotation.ResponseBody; 14 | import org.springframework.web.servlet.ModelAndView; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | 18 | /** 19 | * Created by zhh on 2017/5/5. 20 | */ 21 | @Controller 22 | public class CourseController extends BaseConrtoller{ 23 | 24 | @Autowired 25 | private CourseService courseService; 26 | 27 | /** 28 | * 显示教师自己创建的课程列表 29 | * @param request 30 | * @return 31 | */ 32 | @RequestMapping(value = Url.Course.COURSE_LIST_URL, method = RequestMethod.GET) 33 | public ModelAndView list(HttpServletRequest request){ 34 | return courseService.list(request, getUserId(request)); 35 | } 36 | 37 | /** 38 | * 显示学生选课时的看到的课程列表 39 | * @param request 40 | * @return 41 | */ 42 | @RequestMapping(value = Url.Course.COURSE_LIST_URL_FOR_STU, method = RequestMethod.GET) 43 | public ModelAndView studentlist(HttpServletRequest request){ 44 | return courseService.studentlist(request, getUserId(request)); 45 | } 46 | 47 | /** 48 | * 微信 显示学生选课时的看到的课程列表 49 | * @param request 50 | * @return 51 | */ 52 | @RequestMapping(value = Url.Course.WX_COURSE_LIST_URL_FOR_STU, method = RequestMethod.GET) 53 | public ModelAndView wechatStudentlist(HttpServletRequest request){ 54 | return courseService.wechatStudentlist(request, getUserId(request)); 55 | } 56 | 57 | /** 58 | * 显示管理员选课时的看到的课程列表 59 | * @param request 60 | * @return 61 | */ 62 | @RequestMapping(value = Url.Course.COURSE_LIST_URL_FOR_DDMIN, method = RequestMethod.GET) 63 | public ModelAndView adminlist(HttpServletRequest request){ 64 | return courseService.adminlist(request); 65 | } 66 | 67 | /** 68 | * 添加课程信息 69 | * @param request 70 | * @param course 71 | * @return 72 | */ 73 | @RequestMapping(value = Url.Course.COURSE_ADD_URL, method = RequestMethod.POST) 74 | public ModelAndView addCourse(HttpServletRequest request, Course course){ 75 | course.setTeacherId(getUserId(request)); 76 | return courseService.addCourse(course); 77 | } 78 | 79 | /** 80 | * 更新课程信息 81 | * @param course 82 | * @return 83 | */ 84 | @RequestMapping(value = Url.Course.COURSE_UPDATE_URL, method = RequestMethod.POST) 85 | @ResponseBody 86 | public Object updateCourse(Course course){ 87 | return courseService.updateCourse(course); 88 | } 89 | 90 | /** 91 | * 根据主键获取课程信息 92 | * @param id 93 | * @return 94 | */ 95 | @RequestMapping(value = Url.Course.COURSE_INFO_URL, method = RequestMethod.GET) 96 | @ResponseBody 97 | public Object getCourseInfoById(@PathVariable Integer id){ 98 | return courseService.getCourseInfoById(id); 99 | } 100 | 101 | /** 102 | * 根据主键删除课程信息 103 | * @param id 104 | * @return 105 | */ 106 | @RequestMapping(value = Url.Course.COURSE_DELETE_URL, method = RequestMethod.GET) 107 | public ModelAndView deleteCourseById(@PathVariable Integer id){ 108 | return courseService.deleteCourseById(id); 109 | } 110 | 111 | /** 112 | * 学生选课 113 | * @param request 114 | * @param id 115 | * @return 116 | */ 117 | @RequestMapping(value = Url.Student.STUDENT_CHOOSED_COURSE, method = RequestMethod.GET) 118 | public ModelAndView studentChoosedCourse(HttpServletRequest request, Integer id){ 119 | return courseService.studentChoosedCourse(getUserId(request), id); 120 | } 121 | 122 | /** 123 | * 学生退选 124 | * @param scId 125 | * @param id 126 | * @return 127 | */ 128 | @RequestMapping(value = Url.Student.STUDENT_UNCHOOSED_COURSE, method = RequestMethod.GET) 129 | public ModelAndView studentUnChoosedCourse(HttpServletRequest request, Integer id){ 130 | return courseService.studentUnChoosedCourse(getUserId(request), id); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/controller/web/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.controller.web; 2 | 3 | import com.hus.web.mapper.DepartmentMapper; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.ResponseBody; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * Created by zhh on 2017/3/3. 18 | */ 19 | @Controller 20 | public class DemoController { 21 | 22 | @Autowired 23 | private DepartmentMapper departmentMapper; 24 | @RequestMapping(value = "/home", method = RequestMethod.GET) 25 | public String test() 26 | { 27 | 28 | return "mobile/index"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/controller/web/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.controller.web; 2 | 3 | import com.hus.common.consts.App; 4 | import com.hus.common.consts.Url; 5 | import com.hus.common.consts.View; 6 | import com.hus.web.entity.User; 7 | import com.hus.web.service.LoginService; 8 | import com.hus.web.service.UserService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestMethod; 13 | import org.springframework.web.servlet.ModelAndView; 14 | 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import java.io.IOException; 18 | 19 | /** 20 | * 登录控制器 21 | * Created by zhh on 2017/5/4. 22 | */ 23 | @Controller 24 | public class LoginController { 25 | 26 | @Autowired 27 | private LoginService loginService; 28 | 29 | /** 30 | * 显示登录界面 31 | * @return 32 | */ 33 | @RequestMapping(value = Url.Login.SHOW_LOGIN_PAGE, method = RequestMethod.GET) 34 | public ModelAndView login(HttpServletRequest request) { 35 | return new ModelAndView(View.Index.LOGIN_PAGE); 36 | } 37 | 38 | /** 39 | * PC端登录逻辑 40 | * @param request 41 | * @param sno 42 | * @param password 43 | * @return 44 | */ 45 | @RequestMapping(value = Url.Login.USER_LOGIN_URL, method = RequestMethod.POST) 46 | public ModelAndView userLogin(HttpServletRequest request, String sno, String password){ 47 | return loginService.userLogin(request, sno, password); 48 | } 49 | 50 | /** 51 | * 微信端登录 52 | * @param request 53 | * @return 54 | */ 55 | @RequestMapping(value = Url.Login.WECHAT_USER_LOGIN_URL, method = RequestMethod.GET) 56 | public ModelAndView wechatLogin(HttpServletRequest request) { 57 | return loginService.WechatuserLogin(request); 58 | } 59 | 60 | @RequestMapping(value = "wechat/enter", method = RequestMethod.GET) 61 | public void wechatenter(HttpServletResponse response) throws IOException { 62 | response.sendRedirect("https://open.weixin.qq.com/connect/oauth2/authorize" + 63 | "?appid=wxa4cc0a202b65477c&redirect_uri=http://17157bv023.51mypc.cn/hus/wechat/callback" + 64 | "&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/controller/web/UserController.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.controller.web; 2 | 3 | import com.hus.common.consts.Url; 4 | import com.hus.web.entity.User; 5 | import com.hus.web.service.UserService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.ResponseBody; 12 | import org.springframework.web.servlet.ModelAndView; 13 | 14 | import javax.servlet.http.HttpServletRequest; 15 | import java.util.Map; 16 | 17 | /** 18 | * Created by zhh on 2017/5/5. 19 | */ 20 | @Controller 21 | public class UserController { 22 | 23 | @Autowired 24 | private UserService userService; 25 | @RequestMapping(value = Url.Student.STUDENt_LIST_URL, method = RequestMethod.GET) 26 | public ModelAndView studentlist(HttpServletRequest request){ 27 | return userService.studentList(request); 28 | } 29 | 30 | @RequestMapping(value = Url.Student.STUDENt_ADD_URL, method = RequestMethod.POST) 31 | public ModelAndView addStudent(HttpServletRequest request, User user){ 32 | return userService.addStudent(request, user); 33 | } 34 | 35 | @RequestMapping(value = Url.Student.STUDENT_INFO_URL, method = RequestMethod.GET) 36 | @ResponseBody 37 | public Map getStudentInfo(@PathVariable Integer id){ 38 | return userService.getStudentInfo(id); 39 | } 40 | 41 | @RequestMapping(value = Url.Student.STUDENT_UPDATE_URL, method = RequestMethod.POST) 42 | @ResponseBody 43 | public Object updateStudent(User user){ 44 | return userService.updateStudent(user); 45 | } 46 | 47 | @RequestMapping(value = Url.Student.STUDENT_DELETE_URL, method = RequestMethod.GET) 48 | public ModelAndView deleteStudent(@PathVariable Integer id){ 49 | return userService.delateStudent(id); 50 | } 51 | 52 | 53 | // 教师 54 | @RequestMapping(value = Url.Teacher.TEACHER_LIST_URL, method = RequestMethod.GET) 55 | public ModelAndView teaherlist(HttpServletRequest request){ 56 | return userService.teacherList(request); 57 | } 58 | 59 | @RequestMapping(value = Url.Teacher.TEACHER_ADD_URL, method = RequestMethod.POST) 60 | public ModelAndView addTeacher(HttpServletRequest request, User user){ 61 | return userService.addTeacher(request, user); 62 | } 63 | 64 | @RequestMapping(value = Url.Teacher.TEACHER_UPDATE_URL, method = RequestMethod.POST) 65 | @ResponseBody 66 | public Object updateTeacher(User user){ 67 | return userService.updateTeacher(user); 68 | } 69 | @RequestMapping(value = Url.Teacher.TEACHER_DELETE_URL, method = RequestMethod.GET) 70 | public ModelAndView deleteTeacher(@PathVariable Integer id){ 71 | return userService.delateTeacher(id); 72 | } 73 | @RequestMapping(value = Url.Teacher.TEACHER_INFO_URL, method = RequestMethod.GET) 74 | @ResponseBody 75 | public Map getTeacherInfo(@PathVariable Integer id){ 76 | return userService.getTeacherInfo(id); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/controller/wechat/WechatAuthController.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.controller.wechat; 2 | import com.hus.common.consts.App; 3 | import com.hus.common.consts.Url; 4 | import com.hus.common.consts.View; 5 | import com.hus.common.utils.MyX509TrustManagerUtil; 6 | import com.hus.web.utils.HttpClientUtil; 7 | import io.swagger.annotations.Api; 8 | import net.sf.json.JSONArray; 9 | import net.sf.json.JSONObject; 10 | import org.apache.commons.lang.StringUtils; 11 | import org.apache.log4j.Logger; 12 | import org.springframework.http.MediaType; 13 | import org.springframework.stereotype.Controller; 14 | import org.springframework.web.bind.annotation.CrossOrigin; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.ResponseBody; 17 | import org.springframework.web.servlet.ModelAndView; 18 | 19 | import javax.net.ssl.HttpsURLConnection; 20 | import javax.net.ssl.SSLContext; 21 | import javax.net.ssl.SSLSocketFactory; 22 | import javax.net.ssl.TrustManager; 23 | import javax.servlet.http.HttpServletRequest; 24 | import java.io.BufferedReader; 25 | import java.io.InputStream; 26 | import java.io.InputStreamReader; 27 | import java.io.OutputStream; 28 | import java.net.URL; 29 | 30 | /** 31 | * Created by zhu on 2017/3/15. 32 | */ 33 | @Api(value = "wechat_api", description = "微信相关Api", produces = MediaType.APPLICATION_JSON_VALUE) 34 | @CrossOrigin 35 | @Controller 36 | public class WechatAuthController { 37 | 38 | Logger logger = Logger.getLogger(WechatAuthController.class); 39 | /** 40 | * 微信回调处理(获取用户openId) 41 | * @author 朱昊 42 | * @param code 微信返回,用于获取授权的access token 43 | * @param state 随机字符,用作校验 44 | */ 45 | @RequestMapping(Url.Wechat.CALL_BACK) 46 | // @ResponseBody 47 | public ModelAndView callBack(String code, String state, HttpServletRequest request) 48 | { 49 | if(StringUtils.isBlank(code)){ 50 | request.setAttribute("error_tips", "获取openId失败"); 51 | return new ModelAndView(View.Error.ERROR_PAGE_VIEW); 52 | } 53 | String accessTokenRes = HttpClientUtil.sendPostRequest(String.format(Url.Wechat.AUTH_ACCESS_TOKEN_URL, 54 | App.Wechat.APPID, App.Wechat.APPSECRET, code), null, HttpClientUtil.REQUEST_PARAM_DATA_TYPE_POST); 55 | JSONObject accessTokenJson = JSONObject.fromObject(accessTokenRes); 56 | //授权失败 57 | if (accessTokenJson.containsKey("errcode")) { 58 | String errcode = accessTokenJson.get("errcode").toString(); 59 | String errmsg = accessTokenJson.get("errmsg").toString(); 60 | logger.error("use weixin login err, code " + code + ", errcode " + errcode + ", errmsg " + errmsg); 61 | request.setAttribute("error_tips", "获取openId失败"); 62 | return new ModelAndView(View.Error.ERROR_PAGE_VIEW); 63 | } 64 | request.getSession().setAttribute(App.Session.WECHAT_USER_OPEN_ID, accessTokenJson.getString("openid")); 65 | request.getSession().setAttribute(App.Session.WECHAT_USER_ACCESS_TOKEN, accessTokenJson.getString("access_token")); 66 | // getNormalMenuList(accessTokenJson.getString("access_token")); 67 | return new ModelAndView("redirect:/"+Url.Login.WECHAT_USER_LOGIN_URL); 68 | } 69 | 70 | // /** 71 | // * 获取微信默认菜单 72 | // * @author 张进军 73 | // * @date Jan 27, 2016 11:39:58 AM 74 | // * @param storeId 门店标识 75 | // * @return 微信默认菜单 76 | // */ 77 | // private boolean getNormalMenuList(String accessToken){ 78 | // 79 | // 80 | // JSONObject normalMemu = new JSONObject(); 81 | // String url = Url.Wechat.CREATE_NORMAL_MENU_URL.replace("ACCESS_TOKEN", accessToken); 82 | // JSONObject resultJson =httpRequest(url, "POST", "{\n" + 83 | // " \"button\":[\n" + 84 | // " {\t\n" + 85 | // " \"type\":\"click\",\n" + 86 | // " \"name\":\"今日歌曲\",\n" + 87 | // " \"key\":\"V1001_TODAY_MUSIC\"\n" + 88 | // " },\n" + 89 | // " {\n" + 90 | // " \"name\":\"菜单\",\n" + 91 | // " \"sub_button\":[\n" + 92 | // " {\t\n" + 93 | // " \"type\":\"view\",\n" + 94 | // " \"name\":\"搜索\",\n" + 95 | // " \"url\":\"http://www.soso.com/\"\n" + 96 | // " },\n" + 97 | // " {\n" + 98 | // " \"type\":\"view\",\n" + 99 | // " \"name\":\"视频\",\n" + 100 | // " \"url\":\"http://v.qq.com/\"\n" + 101 | // " },\n" + 102 | // " {\n" + 103 | // " \"type\":\"click\",\n" + 104 | // " \"name\":\"赞一下我们\",\n" + 105 | // " \"key\":\"V1001_GOOD\"\n" + 106 | // " }]\n" + 107 | // " }]\n" + 108 | // " }"); 109 | // if (resultJson.containsKey("errcode") && resultJson.getInt("errcode") != 0) { 110 | // return false; 111 | // } 112 | // return true; 113 | // } 114 | // 115 | // /** 116 | // * HTTPS 请求方式 117 | // * @author 高国藩 118 | // * @date 2015年8月10日 下午11:47:59 119 | // * @param requestUrl 请求链接 120 | // * @param requestMethod 请求方式 121 | // * @param outputStr 请求数据 122 | // * @return 返回json 123 | // */ 124 | // public static JSONObject httpRequest(String requestUrl, 125 | // String requestMethod, String outputStr) { 126 | // JSONObject jsonObject = null; 127 | // StringBuffer buffer = new StringBuffer(); 128 | // try { 129 | // TrustManager[] tm = { new MyX509TrustManagerUtil() }; 130 | // SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE"); 131 | // sslContext.init(null, tm, new java.security.SecureRandom()); 132 | // SSLSocketFactory ssf = sslContext.getSocketFactory(); 133 | // URL url = new URL(requestUrl); 134 | // HttpsURLConnection httpUrlConn = (HttpsURLConnection) url 135 | // .openConnection(); 136 | // httpUrlConn.setSSLSocketFactory(ssf); 137 | // httpUrlConn.setDoOutput(true); 138 | // httpUrlConn.setDoInput(true); 139 | // httpUrlConn.setUseCaches(false); 140 | // httpUrlConn.setRequestMethod(requestMethod); 141 | // if ("GET".equalsIgnoreCase(requestMethod)) { 142 | // httpUrlConn.connect(); 143 | // } 144 | // if (null != outputStr) { 145 | // OutputStream outputStream = httpUrlConn.getOutputStream(); 146 | // outputStream.write(outputStr.getBytes("UTF-8")); 147 | // outputStream.close(); 148 | // } 149 | // InputStream inputStream = httpUrlConn.getInputStream(); 150 | // InputStreamReader inputStreamReader = new InputStreamReader( 151 | // inputStream, "utf-8"); 152 | // BufferedReader bufferedReader = new BufferedReader( 153 | // inputStreamReader); 154 | // String str = null; 155 | // while ((str = bufferedReader.readLine()) != null) { 156 | // buffer.append(str); 157 | // } 158 | // bufferedReader.close(); 159 | // inputStreamReader.close(); 160 | // inputStream.close(); 161 | // inputStream = null; 162 | // httpUrlConn.disconnect(); 163 | // jsonObject = JSONObject.fromObject(buffer.toString()); 164 | // } 165 | // catch (Exception ce) { 166 | // ce.printStackTrace(); 167 | // } 168 | // // logger.info(jsonObject.toString()); 169 | // return jsonObject; 170 | // } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/controller/wechat/WechatEventController.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.controller.wechat; 2 | 3 | import com.hus.common.consts.Url; 4 | import com.hus.web.utils.SignUtil; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | 11 | /** 12 | * Created by zhu on 2017/3/14. 13 | */ 14 | @Controller 15 | public class WechatEventController { 16 | /** 17 | * 18 | * @param signature 微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数 19 | * @param timestamp 时间戳 20 | * @param nonce 随机数 21 | * @param echostr 随机字符串 22 | * @return 23 | */ 24 | @RequestMapping(value = Url.Wechat.CORE_SERVICE, method = RequestMethod.GET) 25 | @ResponseBody 26 | public String chectToken(@RequestParam(value = "signature") String signature, 27 | @RequestParam(value = "timestamp") String timestamp, 28 | @RequestParam(value = "nonce") String nonce, 29 | @RequestParam(value = "echostr") String echostr) { 30 | // 通过检验signature对请求进行校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败 31 | if (SignUtil.checkSignature(signature, timestamp, nonce)) { 32 | return echostr; 33 | } 34 | return "failed!"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/entity/Course.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.entity; 2 | 3 | /** 4 | * Created by zhh on 2017/5/5. 5 | */ 6 | public class Course { 7 | 8 | private Integer id; 9 | 10 | private String sno; 11 | 12 | private String name; 13 | 14 | private Integer teacherId; 15 | 16 | private Integer studyScore; 17 | 18 | private Integer studySlot; 19 | 20 | private String address; 21 | 22 | private Integer status; 23 | 24 | private Integer allQuato; 25 | 26 | private Integer choosedQuato; 27 | 28 | public Course() { 29 | } 30 | 31 | public Integer getId() { 32 | return id; 33 | } 34 | 35 | public void setId(Integer id) { 36 | this.id = id; 37 | } 38 | 39 | public String getSno() { 40 | return sno; 41 | } 42 | 43 | public void setSno(String sno) { 44 | this.sno = sno; 45 | } 46 | 47 | public Integer getTeacherId() { 48 | return teacherId; 49 | } 50 | 51 | public void setTeacherId(Integer teacherId) { 52 | this.teacherId = teacherId; 53 | } 54 | 55 | public Integer getStudyScore() { 56 | return studyScore; 57 | } 58 | 59 | public void setStudyScore(Integer studyScore) { 60 | this.studyScore = studyScore; 61 | } 62 | 63 | public Integer getStudySlot() { 64 | return studySlot; 65 | } 66 | 67 | public void setStudySlot(Integer studySlot) { 68 | this.studySlot = studySlot; 69 | } 70 | 71 | public String getAddress() { 72 | return address; 73 | } 74 | 75 | public void setAddress(String address) { 76 | this.address = address; 77 | } 78 | 79 | public Integer getStatus() { 80 | return status; 81 | } 82 | 83 | public void setStatus(Integer status) { 84 | this.status = status; 85 | } 86 | 87 | public String getName() { 88 | return name; 89 | } 90 | 91 | public void setName(String name) { 92 | this.name = name; 93 | } 94 | 95 | public Integer getChoosedQuato() { 96 | return choosedQuato; 97 | } 98 | 99 | public void setChoosedQuato(Integer choosedQuato) { 100 | this.choosedQuato = choosedQuato; 101 | } 102 | 103 | public Integer getAllQuato() { 104 | return allQuato; 105 | } 106 | 107 | public void setAllQuato(Integer allQuato) { 108 | this.allQuato = allQuato; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/entity/SystemModule.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.entity; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by zhh on 2017/5/4. 7 | */ 8 | public class SystemModule { 9 | 10 | private Integer id; 11 | 12 | private Integer type; 13 | 14 | private String name; 15 | 16 | private String url; 17 | 18 | private Integer parentId; 19 | 20 | private List childrenModule; 21 | 22 | public SystemModule() { 23 | } 24 | 25 | public Integer getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Integer id) { 30 | this.id = id; 31 | } 32 | 33 | public Integer getType() { 34 | return type; 35 | } 36 | 37 | public void setType(Integer type) { 38 | this.type = type; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public String getUrl() { 50 | return url; 51 | } 52 | 53 | public void setUrl(String url) { 54 | this.url = url; 55 | } 56 | 57 | public Integer getParentId() { 58 | return parentId; 59 | } 60 | 61 | public void setParentId(Integer parentId) { 62 | this.parentId = parentId; 63 | } 64 | 65 | public List getChildrenModule() { 66 | return childrenModule; 67 | } 68 | 69 | public void setChildrenModule(List childrenModule) { 70 | this.childrenModule = childrenModule; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.entity; 2 | 3 | /** 4 | * 用户信息实体 5 | * Created by zhh on 2017/5/4. 6 | */ 7 | public class User { 8 | 9 | /** 10 | * 用户唯一标识 11 | */ 12 | private Integer id; 13 | 14 | /** 15 | * 用户角色 1 学生 2 管理员 16 | */ 17 | private Integer type; 18 | 19 | /** 20 | * 用户名 21 | */ 22 | private String sno; 23 | 24 | /** 25 | * 姓名 26 | */ 27 | private String name; 28 | 29 | /** 30 | * 系别 31 | */ 32 | private Integer departmentId; 33 | 34 | /** 35 | * 微信用户唯一标识 36 | */ 37 | private String openId; 38 | 39 | private String password; 40 | 41 | public User() { 42 | } 43 | 44 | public Integer getId() { 45 | return id; 46 | } 47 | 48 | public void setId(Integer id) { 49 | this.id = id; 50 | } 51 | 52 | public String getSno() { 53 | return sno; 54 | } 55 | 56 | public void setSno(String sno) { 57 | this.sno = sno; 58 | } 59 | 60 | public String getName() { 61 | return name; 62 | } 63 | 64 | public void setName(String name) { 65 | this.name = name; 66 | } 67 | 68 | public Integer getDepartmentId() { 69 | return departmentId; 70 | } 71 | 72 | public void setDepartmentId(Integer departmentId) { 73 | this.departmentId = departmentId; 74 | } 75 | 76 | public Integer getType() { 77 | return type; 78 | } 79 | 80 | public void setType(Integer type) { 81 | this.type = type; 82 | } 83 | 84 | 85 | public String getPassword() { 86 | return password; 87 | } 88 | 89 | public String getOpenId() { 90 | return openId; 91 | } 92 | 93 | public void setOpenId(String openId) { 94 | this.openId = openId; 95 | } 96 | 97 | public void setPassword(String password) { 98 | this.password = password; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/mapper/CourseMapper.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.mapper; 2 | 3 | import com.hus.common.consts.Url; 4 | import com.hus.web.entity.Course; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * Created by zhh on 2017/5/5. 12 | */ 13 | public interface CourseMapper { 14 | List> selectAll(); 15 | 16 | Integer insert(Course course); 17 | 18 | Integer update(Course course); 19 | 20 | List> selectByteacherId(Integer teacherId); 21 | 22 | Course selectByPrimaryKey(Integer id); 23 | 24 | Integer delete(Integer id); 25 | 26 | String generateCourseSno(); 27 | 28 | Integer studentChoosedCourse(@Param(value = "studentId") Integer studentId, 29 | @Param(value = "courseId") Integer courseId); 30 | 31 | List> selectAllStudentUnChoosed(Integer studentId); 32 | 33 | List> selectAllStudentChoosed(Integer studentId); 34 | 35 | Integer addChoosedQuota(@Param(value = "num") Integer num, 36 | @Param(value = "courseId")Integer courseId); 37 | Integer deleteStudentCourseByStudentIdAndCourseId(@Param(value = "studentId") Integer studentId, 38 | @Param(value = "courseId")Integer courseId); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/mapper/DepartmentMapper.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.mapper; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | /** 7 | * Created by zhh on 2017/5/5. 8 | */ 9 | public interface DepartmentMapper { 10 | List> selectIdAndDP(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/mapper/SystemModuleMapper.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.mapper; 2 | 3 | import com.hus.web.entity.SystemModule; 4 | 5 | import java.util.List; 6 | 7 | 8 | /** 9 | * Created by zhh on 2017/5/4. 10 | */ 11 | public interface SystemModuleMapper { 12 | 13 | 14 | List selectParentModuleByType(Integer type); 15 | 16 | List selectChildModuleByParentId(Integer parentId); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.mapper; 2 | 3 | import com.hus.web.entity.User; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * Created by zhh on 2017/3/3. 10 | */ 11 | 12 | public interface UserMapper { 13 | 14 | Integer insert(User u); 15 | 16 | Integer update(User u); 17 | 18 | Integer delete(Integer id); 19 | 20 | User selectUserBySno(String sno); 21 | 22 | List> selectStudentInfo(); 23 | 24 | List> selectTeacherInfo(); 25 | 26 | List> selectTeacherMap(); 27 | 28 | Map selectStudentInfoByPrimaryKey(Integer id); 29 | 30 | User selectUserByOpenId(String openId); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/service/CourseService.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.service; 2 | 3 | import com.hus.common.consts.App; 4 | import com.hus.common.consts.Url; 5 | import com.hus.common.consts.View; 6 | import com.hus.web.entity.Course; 7 | import com.hus.web.mapper.CourseMapper; 8 | import com.hus.web.mapper.UserMapper; 9 | import org.springframework.beans.factory.NamedBean; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | import org.springframework.web.servlet.ModelAndView; 14 | 15 | import javax.servlet.http.HttpServletRequest; 16 | import java.util.Map; 17 | 18 | /** 19 | * Created by zhh on 2017/5/5. 20 | */ 21 | @Service 22 | public class CourseService { 23 | 24 | @Autowired 25 | private CourseMapper courseMapper; 26 | 27 | @Autowired 28 | private UserMapper userMapper; 29 | 30 | public ModelAndView list(HttpServletRequest request, Integer teacherId){ 31 | request.setAttribute("course_lists", courseMapper.selectByteacherId(teacherId)); 32 | return new ModelAndView(View.Course.COURSE_LIST_VIEW); 33 | } 34 | 35 | 36 | public ModelAndView studentlist(HttpServletRequest request, Integer studentId){ 37 | request.setAttribute("unchoosed_course_lists", courseMapper.selectAllStudentUnChoosed(studentId)); 38 | request.setAttribute("choosed_course_lists", courseMapper.selectAllStudentChoosed(studentId)); 39 | return new ModelAndView(View.Student.COURSE_LIST_VIEW); 40 | } 41 | 42 | public ModelAndView wechatStudentlist(HttpServletRequest request, Integer studentId){ 43 | request.setAttribute("unchoosed_course_lists", courseMapper.selectAllStudentUnChoosed(studentId)); 44 | request.setAttribute("choosed_course_lists", courseMapper.selectAllStudentChoosed(studentId)); 45 | System.out.println(courseMapper.selectAllStudentUnChoosed(studentId).size()); 46 | System.out.println(courseMapper.selectAllStudentChoosed(studentId).size()); 47 | return new ModelAndView(View.Student.COURSE_LIST_VIEW2); 48 | } 49 | 50 | public ModelAndView addCourse(Course course){ 51 | course.setSno(courseMapper.generateCourseSno()); 52 | courseMapper.insert(course); 53 | return new ModelAndView("redirect:/"+ Url.Course.COURSE_LIST_URL); 54 | } 55 | 56 | public Integer updateCourse(Course course){ 57 | return courseMapper.update(course); 58 | } 59 | 60 | public Course getCourseInfoById(Integer id){ 61 | return courseMapper.selectByPrimaryKey(id); 62 | } 63 | 64 | public ModelAndView deleteCourseById(Integer id){ 65 | courseMapper.delete(id); 66 | return new ModelAndView("redirect:/"+ Url.Course.COURSE_LIST_URL); 67 | } 68 | 69 | @Transactional 70 | public ModelAndView studentChoosedCourse(Integer studentId, Integer courseId){ 71 | courseMapper.addChoosedQuota(1, courseId); 72 | courseMapper.studentChoosedCourse(studentId, courseId); 73 | return new ModelAndView("redirect:/"+Url.Course.COURSE_LIST_URL_FOR_STU); 74 | } 75 | @Transactional 76 | public ModelAndView studentUnChoosedCourse(Integer scId, Integer courseId){ 77 | courseMapper.addChoosedQuota(-1, courseId); 78 | courseMapper.deleteStudentCourseByStudentIdAndCourseId(scId, courseId); 79 | return new ModelAndView("redirect:/"+Url.Course.COURSE_LIST_URL_FOR_STU); 80 | } 81 | 82 | public ModelAndView adminlist(HttpServletRequest request){ 83 | request.setAttribute("course_lists", courseMapper.selectAll()); 84 | return new ModelAndView(View.Course.ADMIN_COURSE_LIST_VIEW); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/service/LoginService.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.service; 2 | 3 | import com.hus.common.consts.App; 4 | import com.hus.common.consts.Url; 5 | import com.hus.common.consts.View; 6 | import com.hus.web.entity.SystemModule; 7 | import com.hus.web.entity.User; 8 | import com.hus.web.mapper.SystemModuleMapper; 9 | import com.hus.web.mapper.UserMapper; 10 | 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | import org.springframework.web.servlet.ModelAndView; 16 | 17 | import javax.servlet.http.HttpServletRequest; 18 | import java.util.List; 19 | 20 | 21 | /** 22 | * Created by zhh on 2017/5/4. 23 | */ 24 | @Service 25 | public class LoginService { 26 | 27 | /** 日志记录对象 */ 28 | private Logger logger = LoggerFactory.getLogger(LoginService.class); 29 | 30 | @Autowired 31 | private SystemModuleMapper systemModuleMapper; 32 | 33 | @Autowired 34 | private UserMapper userMapper; 35 | 36 | public ModelAndView userLogin(HttpServletRequest request, String sno, String password){ 37 | 38 | User user = userMapper.selectUserBySno(sno); 39 | if(user==null){ 40 | //用户不存在 41 | logger.error("用户不存在"); 42 | return new ModelAndView(View.Index.LOGIN_PAGE); 43 | } 44 | if(!user.getPassword().equals(password)){ 45 | //用户不存在 46 | logger.error("密码错误"); 47 | return new ModelAndView(View.Index.LOGIN_PAGE); 48 | } 49 | String openId = (String) request.getSession().getAttribute(App.Session.WECHAT_USER_OPEN_ID); 50 | if(openId!=null){ 51 | user.setOpenId(openId); 52 | userMapper.update(user); 53 | } 54 | request.getSession().setAttribute(App.Session.CURRENT_USER_OBJECT, user); 55 | List list = systemModuleMapper.selectParentModuleByType(user.getType()); 56 | list.stream().forEach((m)->{ 57 | m.setChildrenModule(systemModuleMapper.selectChildModuleByParentId(m.getId())); 58 | }); 59 | request.getSession().setAttribute(App.Session.SYSTEM_MENU_ALL, list); 60 | return new ModelAndView(View.Index.LOGIN_HOME_PAGE); 61 | } 62 | 63 | public ModelAndView WechatuserLogin(HttpServletRequest request){ 64 | String openId = (String) request.getSession().getAttribute(App.Session.WECHAT_USER_OPEN_ID); 65 | User user = userMapper.selectUserByOpenId(openId); 66 | if(user==null){ 67 | return new ModelAndView("redirect:/"+ Url.Login.SHOW_LOGIN_PAGE); 68 | } 69 | request.getSession().setAttribute(App.Session.CURRENT_USER_OBJECT, user); 70 | List list = systemModuleMapper.selectParentModuleByType(user.getType()); 71 | list.stream().forEach((m)->{ 72 | m.setChildrenModule(systemModuleMapper.selectChildModuleByParentId(m.getId())); 73 | }); 74 | request.getSession().setAttribute(App.Session.SYSTEM_MENU_ALL, list); 75 | return new ModelAndView(View.Index.WX_LOGIN_HOME_PAGE); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.service; 2 | 3 | import com.hus.common.consts.Url; 4 | import com.hus.common.consts.View; 5 | import com.hus.web.entity.User; 6 | import com.hus.web.mapper.DepartmentMapper; 7 | import com.hus.web.mapper.UserMapper; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.web.servlet.ModelAndView; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.util.Map; 14 | 15 | /** 16 | * Created by zhh on 2017/5/5. 17 | */ 18 | @Service 19 | public class UserService { 20 | @Autowired 21 | private UserMapper userMapper; 22 | 23 | @Autowired 24 | private DepartmentMapper departmentMapper; 25 | 26 | public ModelAndView studentList(HttpServletRequest request){ 27 | request.setAttribute("student_lists", userMapper.selectStudentInfo()); 28 | request.setAttribute("department_lists", departmentMapper.selectIdAndDP()); 29 | return new ModelAndView(View.Student.STUDENt_LIST_VIEW); 30 | } 31 | 32 | public ModelAndView addStudent(HttpServletRequest request, User user){ 33 | userMapper.insert(user); 34 | return new ModelAndView("redirect:/"+ Url.Student.STUDENt_LIST_URL); 35 | } 36 | 37 | public Map getStudentInfo(Integer id){ 38 | return userMapper.selectStudentInfoByPrimaryKey(id); 39 | } 40 | 41 | public Integer updateStudent(User user){ 42 | return userMapper.update(user); 43 | } 44 | 45 | public ModelAndView delateStudent(Integer id){ 46 | userMapper.delete(id); 47 | return new ModelAndView("redirect:/"+ Url.Student.STUDENt_LIST_URL); 48 | } 49 | 50 | 51 | public ModelAndView teacherList(HttpServletRequest request){ 52 | request.setAttribute("teacher_lists", userMapper.selectTeacherInfo()); 53 | request.setAttribute("department_lists", departmentMapper.selectIdAndDP()); 54 | return new ModelAndView(View.Teacher.TEACHER_LIST_VIEW); 55 | } 56 | 57 | public ModelAndView addTeacher(HttpServletRequest request, User user){ 58 | userMapper.insert(user); 59 | return new ModelAndView("redirect:/"+ Url.Teacher.TEACHER_LIST_URL); 60 | } 61 | 62 | public Integer updateTeacher(User user){ 63 | return userMapper.update(user); 64 | } 65 | 66 | public ModelAndView delateTeacher(Integer id){ 67 | userMapper.delete(id); 68 | return new ModelAndView("redirect:/"+ Url.Teacher.TEACHER_LIST_URL); 69 | } 70 | public Map getTeacherInfo(Integer id){ 71 | return userMapper.selectStudentInfoByPrimaryKey(id); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/hus/web/utils/SignUtil.java: -------------------------------------------------------------------------------- 1 | package com.hus.web.utils; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.util.Arrays; 6 | 7 | /** 8 | * Created by zhu on 2017/3/14. 9 | */ 10 | public class SignUtil { 11 | /** 12 | * 与接口配置信息中的Token要一致 13 | */ 14 | private static String token = "weixinCourse"; 15 | 16 | /** 17 | * 验证签名 18 | * @param signature s 19 | * @param timestamp t 20 | * @param nonce b 21 | * @return boolean b 22 | */ 23 | public static boolean checkSignature(String signature, String timestamp, String nonce) { 24 | String[] arr = new String[] { token, timestamp, nonce }; 25 | // 将token、timestamp、nonce三个参数进行字典序排序 26 | Arrays.sort(arr); 27 | StringBuilder content = new StringBuilder(); 28 | for (int i = 0; i < arr.length; i++) { 29 | content.append(arr[i]); 30 | } 31 | MessageDigest md = null; 32 | String tmpStr = null; 33 | 34 | try { 35 | md = MessageDigest.getInstance("SHA-1"); 36 | // 将三个参数字符串拼接成一个字符串进行sha1加密 37 | byte[] digest = md.digest(content.toString().getBytes()); 38 | tmpStr = byteToStr(digest); 39 | } 40 | catch (NoSuchAlgorithmException e) { 41 | e.printStackTrace(); 42 | } 43 | // 将sha1加密后的字符串可与signature对比,标识该请求来源于微信 44 | return tmpStr != null ? tmpStr.equals(signature.toUpperCase()) : false; 45 | } 46 | 47 | /** 48 | * 将字节数组转换为十六进制字符串 49 | * @param byteArray 数组 50 | * @return String 51 | */ 52 | private static String byteToStr(byte[] byteArray) { 53 | String strDigest = ""; 54 | for (int i = 0; i < byteArray.length; i++) { 55 | strDigest += byteToHexStr(byteArray[i]); 56 | } 57 | return strDigest; 58 | } 59 | 60 | /** 61 | * 将字节转换为十六进制字符串 62 | * @param mByte b 63 | * @return String 64 | */ 65 | private static String byteToHexStr(byte mByte) { 66 | char[] digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 67 | char[] tempArr = new char[2]; 68 | tempArr[0] = digit[(mByte >>> 4) & 0X0F]; 69 | tempArr[1] = digit[mByte & 0X0F]; 70 | 71 | String s = new String(tempArr); 72 | return s; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles.active: dev 3 | mvc.view.prefix: /WEB-INF/view/ 4 | mvc.view.suffix: .jsp 5 | server: 6 | contextPath: /hus 7 | port: 80 8 | 9 | 10 | --- 11 | spring: 12 | profiles: dev 13 | datasource: 14 | driver: com.mysql.jdbc.Driver 15 | url: jdbc:mysql://127.0.0.1:3306/hh 16 | username: root 17 | password: root 18 | wechat: 19 | appID: wxa4cc0a202b65477c 20 | appsecret: 29d8103ec273d5af766ed8ba7eaec315 21 | 22 | -------------------------------------------------------------------------------- /src/main/resources/sqlMap/CourseMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | select 6 | ci.id 'id', 7 | ci.sno 'sno', 8 | ci.name 'name', 9 | ui.name 'teacherName', 10 | ci.address 'address', 11 | ci.study_score 'studyScore', 12 | ci.study_slot 'studySlot', 13 | ci.all_quato 'allQuato', 14 | ci.choosed_quato 'choosedQuato' 15 | from 16 | course_info ci inner join user_info ui on ui.id = ci.teacher_id 17 | 18 | 19 | select 20 | ci.id 'id', 21 | ci.sno 'sno', 22 | ci.name 'name', 23 | ui.name 'teacherName', 24 | ci.address 'address', 25 | ci.study_score 'studyScore', 26 | ci.study_slot 'studySlot', 27 | ci.all_quato 'allQuato', 28 | ci.choosed_quato 'choosedQuato' 29 | from 30 | course_info ci inner join user_info ui on ui.id = ci.teacher_id 31 | where 32 | teacher_id = #{teacherId, jdbcType=INTEGER} 33 | 34 | 35 | insert into course_info 36 | 37 | 38 | sno, 39 | 40 | 41 | name, 42 | 43 | 44 | teacher_id, 45 | 46 | 47 | study_score, 48 | 49 | 50 | study_slot, 51 | 52 | 53 | address, 54 | 55 | 56 | status, 57 | 58 | 59 | all_quato, 60 | 61 | 62 | choosed_quato, 63 | 64 | 65 | 66 | 67 | #{sno, jdbcType=VARCHAR}, 68 | 69 | 70 | #{name, jdbcType=VARCHAR}, 71 | 72 | 73 | #{teacherId, jdbcType=INTEGER}, 74 | 75 | 76 | #{studyScore, jdbcType=INTEGER}, 77 | 78 | 79 | #{studySlot, jdbcType=INTEGER}, 80 | 81 | 82 | #{address, jdbcType=VARCHAR}, 83 | 84 | 85 | #{status, jdbcType=INTEGER}, 86 | 87 | 88 | #{allQuato, jdbcType=INTEGER}, 89 | 90 | 91 | #{choosedQuato, jdbcType=INTEGER}, 92 | 93 | 94 | 95 | 96 | 97 | update course_info 98 | 99 | 100 | sno = #{sno, jdbcType=VARCHAR}, 101 | 102 | 103 | name = #{name, jdbcType=VARCHAR}, 104 | 105 | 106 | teacher_id = #{teacherId, jdbcType=INTEGER}, 107 | 108 | 109 | study_score = #{studyScore, jdbcType=INTEGER}, 110 | 111 | 112 | study_slot = #{studySlot, jdbcType=INTEGER}, 113 | 114 | 115 | address = #{address, jdbcType=VARCHAR}, 116 | 117 | 118 | status = #{status, jdbcType=INTEGER}, 119 | 120 | 121 | all_quato = #{allQuato, jdbcType=INTEGER}, 122 | 123 | 124 | choosed_quato = #{choosedQuato, jdbcType=INTEGER}, 125 | 126 | 127 | where 128 | id = #{id, jdbcType=INTEGER} 129 | 130 | 131 | 132 | select 133 | id as id, 134 | sno as sno, 135 | name as name, 136 | teacher_id as teacherId, 137 | study_score as studyScore, 138 | study_slot as studySlot, 139 | address as address, 140 | status as status, 141 | all_quato as allQuato, 142 | choosed_quato as choosedQuato 143 | from 144 | course_info 145 | where 146 | id = #{id, jdbcType=INTEGER} 147 | 148 | 149 | 150 | delete from course_info where id = #{id, jdbcType=INTEGER} 151 | 152 | 153 | 154 | select max(sno)+1 from course_info; 155 | 156 | 157 | 158 | insert into student_course (student_id, course_id) values (#{studentId, jdbcType=INTEGER}, #{courseId, jdbcType=INTEGER}) 159 | 160 | 161 | 162 | select 163 | ci.id 'id', 164 | ci.sno 'sno', 165 | ci.name 'name', 166 | ui.name 'teacherName', 167 | ci.address 'address', 168 | ci.study_score 'studyScore', 169 | ci.study_slot 'studySlot', 170 | ci.all_quato 'allQuato', 171 | ci.choosed_quato 'choosedQuato' 172 | from 173 | course_info ci inner join user_info ui on ui.id = ci.teacher_id 174 | where 175 | ci.id not in 176 | ( 177 | SELECT course_id from student_course sc WHERE sc.student_id=#{studentId, jdbcType=INTEGER} 178 | ) 179 | 180 | 181 | 182 | select 183 | ci.id 'id', 184 | ci.sno 'sno', 185 | ci.name 'name', 186 | ui.name 'teacherName', 187 | ci.address 'address', 188 | ci.study_score 'studyScore', 189 | ci.study_slot 'studySlot', 190 | ci.all_quato 'allQuato', 191 | ci.choosed_quato 'choosedQuato' 192 | from 193 | course_info ci inner join user_info ui on ui.id = ci.teacher_id 194 | where 195 | ci.id in 196 | ( 197 | SELECT course_id from student_course sc WHERE sc.student_id=#{studentId, jdbcType=INTEGER} 198 | ) 199 | 200 | 201 | 202 | update course_info 203 | set choosed_quato = choosed_quato + #{num, jdbcType=INTEGER } 204 | where id = #{courseId, jdbcType=INTEGER} 205 | 206 | 207 | 208 | delete from student_course where student_id = #{studentId, jdbcType=INTEGER} and course_id = #{courseId, jdbcType=INTEGER} 209 | 210 | 211 | -------------------------------------------------------------------------------- /src/main/resources/sqlMap/DepartmentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SELECT 6 | concat(id,'') 'id', 7 | concat(departmemt, '---', prefession,'(', grade, ')') 'department' 8 | FROM 9 | department_info 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/resources/sqlMap/SystemModuleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | select 6 | id as id, 7 | type as type, 8 | name as name, 9 | url as url, 10 | parent_id as parentId 11 | from 12 | system_module 13 | where 14 | type = #{type, jdbcType=INTEGER} and parent_id = 0 15 | 16 | 17 | 18 | select 19 | id as id, 20 | type as type, 21 | name as name, 22 | url as url, 23 | parent_id as parentId 24 | from 25 | system_module 26 | where 27 | parent_id = #{parentId, jdbcType=INTEGER} 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/resources/sqlMap/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | insert into user_info 6 | 7 | 8 | type, 9 | 10 | 11 | sno, 12 | 13 | 14 | password, 15 | 16 | 17 | name, 18 | 19 | 20 | department_id, 21 | 22 | 23 | open_id, 24 | 25 | 26 | 27 | 28 | #{type, jdbcType=INTEGER}, 29 | 30 | 31 | #{sno,jdbcType=VARCHAR}, 32 | 33 | 34 | #{password,jdbcType=VARCHAR}, 35 | 36 | 37 | #{name, jdbcType=VARCHAR}, 38 | 39 | 40 | #{departmentId, jdbcType=INTEGER}, 41 | 42 | 43 | #{openId, jdbcType=VARCHAR}, 44 | 45 | 46 | 47 | 48 | update user_info 49 | 50 | 51 | type = #{type, jdbcType=INTEGER}, 52 | 53 | 54 | sno = #{sno,jdbcType=VARCHAR}, 55 | 56 | 57 | password = #{password,jdbcType=VARCHAR}, 58 | 59 | 60 | name = #{name, jdbcType=VARCHAR}, 61 | 62 | 63 | department_id = #{departmentId, jdbcType=INTEGER}, 64 | 65 | 66 | open_id = #{openId, jdbcType=VARCHAR}, 67 | 68 | 69 | where 70 | id = #{id, jdbcType=INTEGER} 71 | 72 | 73 | SELECT 74 | id as id, 75 | type as type, 76 | sno as sno, 77 | name as name, 78 | department_id as departmentId, 79 | password as password, 80 | open_id as openId 81 | from 82 | user_info 83 | where 84 | sno = #{sno, jdbcType=VARCHAR} 85 | 86 | 87 | 88 | SELECT 89 | id as id, 90 | type as type, 91 | sno as sno, 92 | name as name, 93 | department_id as departmentId, 94 | password as password, 95 | open_id as openId 96 | from 97 | user_info 98 | where 99 | open_id = #{openId, jdbcType=VARCHAR} 100 | 101 | 102 | 103 | select 104 | ui.id 'id', 105 | ui.sno 'sno', 106 | ui.name 'name', 107 | di.departmemt 'department', 108 | di.prefession 'prefession', 109 | di.grade 'grade' 110 | from 111 | user_info ui left join department_info di on ui.department_id = di.id 112 | where 113 | ui.type=1; 114 | 115 | 116 | 117 | select 118 | ui.id 'id', 119 | ui.sno 'sno', 120 | ui.name 'name', 121 | di.departmemt 'department', 122 | di.prefession 'prefession', 123 | di.grade 'grade' 124 | from 125 | user_info ui left join department_info di on ui.department_id = di.id 126 | where 127 | ui.type=2; 128 | 129 | 130 | 131 | 132 | select 133 | concat('',id) 'id', 134 | sno 'sno', 135 | name 'name', 136 | concat('',department_id) 'departmentId', 137 | password 'password' 138 | from 139 | user_info 140 | where 141 | id = #{id, jdbcType=INTEGER} 142 | 143 | 144 | 145 | delete from user_info where id = #{id, jdbcType=INTEGER} 146 | 147 | 148 | 149 | SELECT 150 | concat(id,'') 'id', 151 | concat(name,'(', sno, ')') 'name' 152 | FROM 153 | user_info 154 | WHERE 155 | type = 2 156 | 157 | 158 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/view/error.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: zhh 4 | Date: 2017/5/10 5 | Time: 13:10 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 错误 12 | 13 | 14 | ${error_tips} 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/view/home/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: zhh 4 | Date: 2017/5/4 5 | Time: 15:42 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> 9 | <%@ include file="/base.jsp" %> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | <%@include file="/nav.jsp"%> 22 | 23 | 24 | 25 | <%@include file="/menu.jsp"%> 26 | 27 | 28 | 主窗口 29 | 30 | 31 | 32 | 34 | 35 |