这是applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<context:property-placeholder location=“classpath:database.properties”/>
<!-- mapper工厂 为接口创建对象 -->
<bean id="factoryMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="cn.dao.UserMapper"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
<!-- service -->
<!-- <bean id="userService" class="cn.service.impl.StudentServiceImpl" p:usermapper-ref="factoryMapper">
</bean> -->
dispatcherServlet-servlert.xml文件
<?xml version="1.0" encoding="UTF-8"?>mvc:annotation-driven/
<context:component-scan base-package=“cn”></context:component-scan>
<mvc:resources location="/statics/" mapping="/statics/**"></mvc:resources>
<!-- 出现异常后的处理页面 -->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">error</prop>
</props>
</property>
</bean>
<!-- 配置拦截上传内容 -->
<!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10000000"></property>
</bean>-->
web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
controller文件
package cn.controller;
import cn.entity.User;
import cn.service.*;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/user")
public class UserController {
@Resource
private UserService userService;
@ResponseBody
@RequestMapping(value="/loginUser",method=RequestMethod.POST)
public String loginUser(User user) {
User u = userService.loginUser(user);
String mess="error";
mess=u==null?mess:"ok";
return mess;
}
}
loginUser.jsp页面
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
用户名:
密码: