Tomcat + javaWeb + spring is an urban supply and demand management system.

Source: Internet
Author: User

Tomcat + javaWeb + spring is an urban supply and demand management system.

This is the first small project to learn javaweb by myself. It also follows the video and is from java1234.Xiao FengThere are a lot of java videos for your reference.TomcatAs the backend, and (• yunω • Yun) y is usedStruct and hiberateThese two frameworksStruct and hiberateNot familiar, so you can directly use it after watching the video.Spring frameworkWrite one by yourself, which can be used as a reference for learning;

Main interfaces:

  The most important Homepage

 

Information details page

 

Information List page

 

Information Publishing Page

 

Background review page

 

  

This is the main structure of the project:

// Db_cityinfo DATABASE table, create database /*! 32312 if not exists */'db _ cityinfo '/*! 40100 default character set utf8 */; USE 'db _ cityinfo'; // Several fields defined in the t_info TABLE information drop table if exists 't_info '; create table 't_ info' ('id' int (11) not null AUTO_INCREMENT, 'typeid' int (11) default null, 'title' varchar (40) default null, 'content' text, 'linkman' varchar (20) default null, 'phone' varchar (20) default null, 'email 'varchar (20) default null, 'infodate' datetime default null, 'state' int (11) default null, 'payfor 'int (11) default null, primary key ('id ')) ENGINE = InnoDB AUTO_INCREMENT = 54 default charset = utf8; // drop table if exists 't_ infotype' in the fields defined in the t_infotype TABLE type '; create table 't_ infotype' ('id' int (11) not null AUTO_INCREMENT, 'typesign' int (11) default null, 'typename' varchar (20) default null, primary key ('id') ENGINE = InnoDB AUTO_INCREMENT = 12 default charset = utf8; // t_user user TABLE; drop table if exists 't_ user '; create table 't_user' ('id' int (11) not null AUTO_INCREMENT, 'username' varchar (20) default null, 'Password' varchar (20) default null, primary key ('id') ENGINE = InnoDB AUTO_INCREMENT = 2 default charset = utf8;

The database is the data persistence layer.CRUD (add, delete, modify, and query), You do not need to understand too much;

RelatedRoutingAndDatabase OperationsAll in the com. nono package;

<? Xml version = "1.0" encoding = "UTF-8"?> <Web-app version = "3.0" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name> </display-name> <! --- Default access address ---> <welcome-file-list> <welcome-file> index.htm </welcome-file> </welcome-file-list> <servlet -name> test </servlet-name> <servlet-class> org. springframework. web. servlet. dispatcherServlet </servlet-class> <load-on-startup> 1 </load-on-startup> </servlet> <! ---All files with the suffix of request .htm are routed through servlet ---> <servlet-mapping> <servlet-name> test </servlet-name> <url-pattern> *. htm </url-pattern> </servlet-mapping> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> <! --- This points to the xml configuration of spring ---> <context-param> <param-name> contextConfigLocation </param-name> <param-value>/WEB-INF/test-servlet.xml </param -value> </context-param> </web-app>

 

This isTest-servlet.xmlFile

<? 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: p = "http://www.springframework.org/schema/p" xmlns: context = "http://www.springframework.org/schema/context" xmlns: aop = "http://www.springframework.org/schema/aop" xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: mvc = "http://www.springframework.org/schema/mvc" xmlns: task = "http://www.springframework.org/schema/task" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> // Let spring automatically scan com. <context: annotation-config> </context: annotation-config> <context: component-scan base-package = "com. nono "> </context: component-scan>
// This is the bean configuration of mysql, Which is configured as my local database, the connected database is test, the account is root, and the password is 6 and 1; <bean name = "dataSource" class = "org. springframework. jdbc. datasource. driverManagerDataSource "> <property name =" driverClassName "value =" com. mysql. jdbc. driver "/> <property name =" url "value =" jdbc: mysql: // 127.0.0.1: 3306/test "/> <property name =" username "value =" root "/> <property name =" password "value =" 111111 "/> </bean>
// We need to put the configuration dataSource in jdbcTemplate, and follow the normal logic to <bean id = "jdbcTemplate" class = "org. springframework. jdbc. core. jdbcTemplate "abstract =" false "lazy-init =" false "autowire =" default "> <! -- Pass this bean in --> <property name = "dataSource" ref = "dataSource"> </property> </bean>
// We generated a bean called jdbcDao, which is stored in com. if the nono package uses jdbcDao, add @ Autowired directly before the declaration, then the bean will be automatically injected. If you don't understand it, you can check what the servlet bean is; <bean id = "jdbcDao" class = "com. nono. dao. jdbcDao "> <property name =" jdbcTemplate "ref =" jdbcTemplate "> </property> </bean>
// This is also the configuration. add all the ModelAndView strings returned by the Controller. jsp serves as the end for convenience. <bean id = "viewResolver" class = "org. springframework. web. servlet. view. internalResourceViewResolver "> <property name =" suffix "> <value>. jsp </value> </property> </bean> </beans>

 

  WebRootCode andSrcThe Code address in the folder has been uploaded to the blog,Click to download 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.