搭建一个简单的springMvc框架
springmvc.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd"
xmlns:task="http://www.springframework.org/schema/task">
<!--1、开启注解模式-->
<mvc:annotation-driven/>
<!--4、扫描所有的控制器类-->
<context:component-scan base-package="controller"/>
<!--配置WEB-INF下面的资源可以访问-->
<mvc:resources mapping="/css/**" location="/easyui/css/"/>
<mvc:resources mapping="/js/**" location="/easyui/js/"/>
<mvc:resources mapping="/qrcode/**" location="/WEB-INF/classes/file/qrcode/" />
<!--3、视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> -->
<property name="prefix" value="/WEB-INF/me"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
//web 文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>weixinxiaochengxun</display-name>
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springMVC.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>*.do</url-pattern>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:mybatis-confg.xml</param-value>
</context-param>
</web-app>
//控制层
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package controller;
import bean.WxAccessToken;
import bean.WxUserInfo;
import constant.WeChatConstant;
import service.IWeChatService;
import org.springframework.web.bind.annotation.*;
/**
* 控制器
*
* @author Chill
*/
//@ApiIgnore
@RestController
@RequestMapping("/wechat")
public class WeChatController {
private IWeChatService service;
/**
* 网页授权token
*/
@GetMapping("/token")
public WxAccessToken weChatAccessToken(String appid, String secret, String code, String grantType){
System.out.println("进入微信网页授权》》》》》》》》》》》》》》》");
WxAccessToken token = service.weChatAccessToken(WeChatConstant.appid,WeChatConstant.secret,code,grantType);
System.out.println("token======="+token);
return token;
}
/**
* 用户信息
*/
@GetMapping("/info")
public WxUserInfo weChatUserInfo(String accessToken, String openId, String lang){
WxUserInfo wxUserInfo = service.weChatUserInfo(accessToken,openId,lang);
return wxUserInfo;
}
}


浙公网安备 33010602011771号