超市账单管理系统之-------登录
报500的错大部分都是springmvc的jar包没有导对,最好用3点几的版本 。。。。在项目中要把包导对
pom.xml
所需要的jar包
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>cn.happy</groupId> 5 <artifactId>01sup</artifactId> 6 <packaging>war</packaging> 7 <version>1.0-SNAPSHOT</version> 8 <name>01sup Maven Webapp</name> 9 <url>http://maven.apache.org</url> 10 <dependencies> 11 <dependency> 12 <groupId>junit</groupId> 13 <artifactId>junit</artifactId> 14 <version>4.3</version> 15 <scope>test</scope> 16 </dependency> 17 <dependency> 18 <groupId>org.springframework</groupId> 19 <artifactId>spring-context</artifactId> 20 <version>4.2.0.RELEASE</version> 21 </dependency> 22 23 <dependency> 24 <groupId> org.aspectj</groupId > 25 <artifactId> aspectjweaver</artifactId > 26 <version> 1.8.7</version > 27 </dependency> 28 29 <dependency> 30 <groupId>org.springframework</groupId> 31 <artifactId>spring-webmvc</artifactId> 32 <version>3.2.4.RELEASE</version> 33 </dependency> 34 35 <!--SpringWeb--> 36 <dependency> 37 <groupId>org.springframework</groupId> 38 <artifactId>spring-web</artifactId> 39 <version>4.1.8.RELEASE</version> 40 </dependency> 41 42 <!--ServletAPI--> 43 <dependency> 44 <groupId>javaee</groupId> 45 <artifactId>javaee-api</artifactId> 46 <version>5</version> 47 </dependency> 48 49 <dependency> 50 <groupId>javax.servlet</groupId> 51 <artifactId>jstl</artifactId> 52 <version>1.2</version> 53 <scope>runtime</scope> 54 </dependency> 55 56 <!--fastjson的jar包--> 57 <dependency> 58 <groupId>com.alibaba</groupId> 59 <artifactId>fastjson</artifactId> 60 <version>1.2.9</version> 61 </dependency> 62 63 <!--jacksonjar包--> 64 <dependency> 65 <groupId>com.fasterxml.jackson.core</groupId> 66 <artifactId>jackson-core</artifactId> 67 <version>2.5.4</version> 68 </dependency> 69 70 <dependency> 71 <groupId>com.fasterxml.jackson.core</groupId> 72 <artifactId>jackson-annotations</artifactId> 73 <version>2.5.0</version> 74 </dependency> 75 76 77 <dependency> 78 <groupId>com.fasterxml.jackson.core</groupId> 79 <artifactId>jackson-databind</artifactId> 80 <version>2.5.4</version> 81 </dependency> 82 83 <!--数据验证--> 84 <dependency> 85 <groupId>org.hibernate</groupId> 86 <artifactId>hibernate-validator</artifactId> 87 <version>4.0.1.GA</version> 88 </dependency> 89 90 91 <!--jboss logging--> 92 <dependency> 93 <groupId>org.jboss.logging</groupId> 94 <artifactId>jboss-logging</artifactId> 95 <version>3.3.0.Final</version> 96 </dependency> 97 98 <!--validation api--> 99 <dependency> 100 <groupId>javax.validation</groupId> 101 <artifactId>validation-api</artifactId> 102 <version>1.0.0.GA</version> 103 </dependency> 104 105 <!--slf4j api--> 106 <dependency> 107 <groupId>org.slf4j</groupId> 108 <artifactId>slf4j-api</artifactId> 109 <version>1.7.21</version> 110 </dependency> 111 112 113 <!--文件上传的jar包--> 114 115 <dependency> 116 <groupId>commons-fileupload</groupId> 117 <artifactId>commons-fileupload</artifactId> 118 <version>1.3.1</version> 119 </dependency> 120 121 <dependency> 122 <groupId>commons-io</groupId> 123 <artifactId>commons-io</artifactId> 124 <version>1.4</version> 125 </dependency> 126 127 <dependency> 128 <groupId>org.springframework</groupId> 129 <artifactId>spring-tx</artifactId> 130 <version>4.2.5.RELEASE</version> 131 </dependency> 132 133 <!--Mybatis jar --> 134 135 <!--mysql数据库驱动--> 136 <dependency> 137 <groupId>org.wisdom-framework</groupId> 138 <artifactId>mysql-connector-java</artifactId> 139 <version>5.1.34_1</version> 140 </dependency> 141 142 <!--mybatis jar包--> 143 <dependency> 144 <groupId>org.mybatis</groupId> 145 <artifactId>mybatis</artifactId> 146 <version>3.2.2</version> 147 </dependency> 148 149 <!--Mybatis+Spring整合--> 150 <dependency> 151 <groupId>org.mybatis</groupId> 152 <artifactId>mybatis-spring</artifactId> 153 <version>1.3.1</version> 154 </dependency> 155 156 <!--c3p0--> 157 <dependency> 158 <groupId>com.mchange</groupId> 159 <artifactId>c3p0</artifactId> 160 <version>0.9.5.2</version> 161 </dependency> 162 163 <dependency> 164 <groupId>org.springframework</groupId> 165 <artifactId>spring-jdbc</artifactId> 166 <version>4.2.5.RELEASE</version> 167 </dependency> 168 169 <dependency> 170 <groupId>com.google.code.gson</groupId> 171 <artifactId>gson</artifactId> 172 <version>2.8.0</version> 173 </dependency> 174 175 </dependencies> 176 177 <build> 178 <resources> 179 <resource> 180 <directory>src/main/java</directory> 181 <includes> 182 <include>**/*.xml</include> 183 </includes> 184 </resource> 185 </resources> 186 </build> 187 </project>
1.
先编写实体类
1 public class UserInfo { 2 private Integer id; //id 3 private String userCode; //用户编码 4 private String userName; //用户名称 5 private String userPassword; //用户密码 6 private Integer gender; //性别 7 private Date birthday; //出生日期 8 private String phone; //电话 9 private String address; //地址 10 private Integer userRole; //用户角色 11 private Integer createdBy; //创建者 12 private Date creationDate; //创建时间 13 private Integer modifyBy; //更新者 14 private Date modifyDate; //更新时间 15 16 17 }
2.dao层
1 //登录的方法 2 public UserInfo isLogin(UserInfo info);//登录
dao层中的xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper 3 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5 <mapper namespace="cn.smbms.dao.IUserInfoDAO"> 6 <!--1.登录--> 7 <select id="isLogin" parameterType="UserInfo" resultType="UserInfo"> 8 select usercode,userName from smbms_user where usercode=#{userCode} and userPassword=#{userPassword} 9 </select> 10 11 </mapper>
3.service层
1 //登录的方法 2 public UserInfo isLogin(UserInfo info);
1 @Service("useService") 2 public class UserInfoServiceImpl implements IUserInfoService { 3 //植入dao对象 4 @Resource(name = "IUserInfoDAO") 5 IUserInfoDAO userInfoDAO; 6 public UserInfo isLogin(UserInfo info) { 7 return userInfoDAO.isLogin(info); 8 } 9 }
4.controller包下定义一个类植入service
1 @Controller 2 @RequestMapping("/user") 3 public class UserInfoController { 4 //植入service 5 @Resource(name ="useService" ) 6 IUserInfoService userInfoService; 7 8 //登录方法 9 @RequestMapping("/doLogin") 10 public String doLogin(HttpSession session, UserInfo info){ 11 UserInfo user = userInfoService.isLogin(info); 12 if (user!=null&&user.getUserName()!=null){ 13 //登录成功 14 session.setAttribute("userinfo",user.getUserName()); 15 return "welcome"; 16 }else { 17 //登录失败 18 return "login"; 19 } 20 } 21 }
5.applicationContext.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:aop="http://www.springframework.org/schema/aop" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xmlns:tx="http://www.springframework.org/schema/tx" 7 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 8 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 9 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 10 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 11 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 12 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 13 "> 14 <!--包扫描器--> 15 <context:component-scan base-package="cn.smbms"></context:component-scan> 16 <!--mvc注解驱动 作用:创建7个HttpMessaeingConvert--> 17 <mvc:annotation-driven></mvc:annotation-driven> 18 <!--视图解析器--> 19 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 20 <property name="prefix" value="/jsp/"></property> 21 <property name="suffix" value=".jsp"></property> 22 </bean> 23 24 <!--识别到jdbc.properties--> 25 <context:property-placeholder location="classpath:jdbc.properties"/> 26 <!--1.数据源--> 27 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 28 <property name="driverClass" value="${jdbc.driver}"></property> 29 <property name="jdbcUrl" value="${jdbc.url}"></property> 30 <property name="user" value="${jdbc.username}"></property> 31 <property name="password" value="${jdbc.password}"></property> 32 </bean> 33 34 <!--2.sqlSessionFactory--> 35 <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 36 <property name="dataSource" ref="dataSource"></property> 37 <property name="configLocation" value="classpath:MyBatis-config.xml"></property> 38 </bean> 39 40 <!--3.dao 认识到Mapper--> 41 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 42 <property name="basePackage" value="cn.smbms.dao"></property> 43 </bean> 44 45 <!--5.事务管理器--> 46 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 47 <property name="dataSource" ref="dataSource"></property> 48 </bean> 49 50 <!--6.事务--> 51 <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven> 52 53 54 </beans>
6.连接到MSQ数据库 jdbc.properties
1 jdbc.driver=com.mysql.jdbc.Driver 2 jdbc.url=jdbc:mysql:///smbms 3 jdbc.username=root 4 jdbc.password=root
7.MyBatis-config.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE configuration 3 PUBLIC "-//mybatis.org//DTD Config 3.0//EN" 4 "http://mybatis.org/dtd/mybatis-3-config.dtd"> 5 <configuration> 6 <!--别名--> 7 <typeAliases> 8 <package name="cn.smbms.entity"></package> 9 </typeAliases> 10 <!-- <!–关联小配置–> 11 <mappers> 12 <mapper resource="cn/sale/dao/IUserDAO.xml"/> 13 </mappers>--> 14 15 </configuration>
8.web.xml
1 <!DOCTYPE web-app PUBLIC 2 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 3 "http://java.sun.com/dtd/web-app_2_3.dtd" > 4 5 <web-app> 6 <display-name>Archetype Created Web Application</display-name> 7 <context-param> 8 <param-name>contextConfigLocation</param-name> 9 <param-value>classpath:applicationContext.xml</param-value> 10 </context-param> 11 12 <filter> 13 <filter-name>CharactorEncodingFilter</filter-name> 14 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 15 <init-param> 16 <param-name>encoding</param-name> 17 <param-value>utf-8</param-value> 18 </init-param> 19 <init-param> 20 <param-name>forceEncoding</param-name> 21 <param-value>true</param-value> 22 </init-param> 23 </filter> 24 <filter-mapping> 25 <filter-name>CharactorEncodingFilter</filter-name> 26 <url-pattern>/*</url-pattern> 27 </filter-mapping> 28 29 <!--监听器--> 30 <listener> 31 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 32 </listener> 33 <servlet> 34 <servlet-name>springmvc</servlet-name> 35 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 36 <init-param> 37 <param-name>contextConfigLocation</param-name> 38 <param-value>classpath:applicationContext.xml</param-value> 39 </init-param> 40 <load-on-startup>1</load-on-startup> 41 </servlet> 42 <servlet-mapping> 43 <servlet-name>springmvc</servlet-name> 44 <url-pattern>/</url-pattern> 45 </servlet-mapping> 46 <servlet-mapping> 47 <servlet-name>default</servlet-name> 48 <url-pattern>*.js</url-pattern> 49 </servlet-mapping> 50 <servlet-mapping> 51 <servlet-name>default</servlet-name> 52 <url-pattern>*.css</url-pattern> 53 </servlet-mapping> 54 <servlet-mapping> 55 <servlet-name>default</servlet-name> 56 <url-pattern>*.jpg</url-pattern> 57 </servlet-mapping> 58 <servlet-mapping> 59 <servlet-name>default</servlet-name> 60 <url-pattern>*.bmp</url-pattern> 61 </servlet-mapping> 62 <servlet-mapping> 63 <servlet-name>default</servlet-name> 64 <url-pattern>*.gif</url-pattern> 65 </servlet-mapping> 66 <servlet-mapping> 67 <servlet-name>default</servlet-name> 68 <url-pattern>*.png</url-pattern> 69 </servlet-mapping> 70 </web-app>
9.把longin.xml 和welcome.xml修改为jsp形式
login.jsp
1 <%@ page pageEncoding="utf-8" isELIgnored="false" %> 2 <!DOCTYPE html> 3 <html> 4 <head lang="en"> 5 <meta charset="UTF-8"> 6 <title>系统登录 - 超市账单管理系统</title> 7 <link rel="stylesheet" href="css/style.css"/> 8 </head> 9 <body class="login_bg"> 10 <section class="loginBox"> 11 <header class="loginHeader"> 12 <h1>超市账单管理系统</h1> 13 </header> 14 <section class="loginCont"> 15 <form class="loginForm" action="${pageContext.request.contextPath}/user/doLogin"> 16 <div class="inputbox"> 17 <label for="user">用户名:</label> 18 <input id="user" type="text" name="userCode" placeholder="请输入用户名" required/> 19 </div> 20 <div class="inputbox"> 21 <label for="mima">密码:</label> 22 <input id="mima" type="password" name="userPassword" placeholder="请输入密码" required/> 23 </div> 24 <div class="subBtn"> 25 <input type="submit" value="登录" /> 26 <input type="reset" value="重置"/> 27 </div> 28 29 </form> 30 </section> 31 </section> 32 33 </body> 34 </html>
welcome.jsp
1 <%@ page pageEncoding="utf-8" isELIgnored="false" %> 2 <!DOCTYPE html> 3 <html> 4 <head lang="en"> 5 <meta charset="UTF-8"> 6 <title>超市账单管理系统</title> 7 <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/css/public.css"/> 8 <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/css/style.css"/> 9 </head> 10 <body> 11 <!--头部--> 12 <header class="publicHeader"> 13 <h1>超市账单管理系统</h1> 14 15 <div class="publicHeaderR"> 16 <p><span>下午好!</span><span style="color: #fff21b"> Admin</span> , 欢迎你!</p> 17 <a href="login.html">退出</a> 18 </div> 19 </header> 20 <!--时间--> 21 <section class="publicTime"> 22 <span id="time">2015年1月1日 11:11 星期一</span> 23 <a href="#">温馨提示:为了能正常浏览,请使用高版本浏览器!(IE10+)</a> 24 </section> 25 <!--主体内容--> 26 <section class="publicMian"> 27 <div class="left"> 28 <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2> 29 <nav> 30 <ul class="list"> 31 <li ><a href="billList.html">账单管理</a></li> 32 <li><a href="providerList.html">供应商管理</a></li> 33 <li><a href="userList.html">用户管理</a></li> 34 <li><a href="password.html">密码修改</a></li> 35 <li><a href="login.html">退出系统</a></li> 36 </ul> 37 </nav> 38 </div> 39 <div class="right"> 40 <img class="wColck" src="${pageContext.request.contextPath}/jsp/img/clock.jpg" alt=""/> 41 <div class="wFont"> 42 <h2>Admin</h2> 43 <p>欢迎来到超市账单管理系统!</p> 44 </div> 45 </div> 46 </section> 47 <footer class="footer"> 48 版权归北大青鸟 49 </footer> 50 <script src="${pageContext.request.contextPath}/jsp/js/time.js"></script> 51 </body> 52 </html>
以上只是一个登录实现的功能。。。。以后会陆续实现没有完成的功能块,尽情期待吧!
作者:Fry
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利.如有问题,请与作者联系:1203905913@qq.com