Development Steps and Architecture

Posted by arunmj82 on Mon, 30 Sep 2019 13:17:08 +0200

0. Simple Course Management

0.1 Establishment of database tables
  • MySQL
	create table t_teachers (
		id int(5) primary key ,
		username varchar(30) unique not null ,
		password varchar(32) not null ,
		name varchar(100) ,
		gender varchar(6),
		birthdate date
	);

Note that id is the primary key in the database table

  • Oracle
	create table t_teachers (
		id number(5) primary key ,
		username varchar2(30) unique not null ,
		password varchar2(32) not null ,
		name varchar2(100) ,
		gender varchar2(6),
		birthdate date
	);
  • insert data
	insert into t_teachers ( id , username , password , name , gender ) values ( 1 , 'laosun' , 'meiyoumima' ,'Old sun' , 'male' ) ;
	insert into t_teachers ( id , username , password  ) values ( 2 , 'laowang' , 'gebilaowang' ) ;
	insert into t_teachers ( id , username , password  ) values ( 3 , 'wangyi' , 'xiaowang' ) ;
  • record/relationship/entity
0.2 Establishing Entity Classes
  • Starting with the Web phase, all entity classes implement serialized interfaces

  • Creating Teacher Entity Classes

	import java.util.Date ;
	
	public class Teacher {
		private Integer id ; // Object Identity (zhi) Character Properties [Object Identity (zhi) Character Field]
		private String username ;
		private String password ;
		private String name ;
		private String gender ;
		private Date birthdate ;
		// getter .... setter ....
	}

1. Setting up Environment

2. Adding filters

2.1 Development of filter classes
package cn.itlaobing.filter;

import java.io.IOException;
import java.nio.charset.Charset;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterEncodingFilter implements Filter {
	
	private static final String ENCODING_PARAM = "encoding" ;
	private static final String DEFAULT_CHARSET = "UTF-8" ;
	
	private String encoding ; // Names used to store character codes read from initialization parameters
	
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		encoding = filterConfig.getInitParameter( ENCODING_PARAM );
		encoding = ( encoding == null || encoding.trim().isEmpty() ) ? DEFAULT_CHARSET : encoding  ;
		encoding = Charset.isSupported( encoding ) ? encoding : DEFAULT_CHARSET ; 
	}

	@Override
	public void doFilter(ServletRequest req , ServletResponse resp , FilterChain chain)
			throws IOException, ServletException {
		// Setting the encoding of requests and responses
		req.setCharacterEncoding( this.encoding );
		resp.setCharacterEncoding( this.encoding );
		// Pass back requests and responses through the filter chain
		chain.doFilter(req, resp);
	}
	
	@Override
	public void destroy() {
	}

}
	
2.2 Deployment of filters
	<filter>
		<filter-name>characterEncodingFilter</filter-name>
		<filter-class>cn.itlaobing.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	
	<filter-mapping>
		<filter-name>characterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>INCLUDE</dispatcher>
		<dispatcher>ERROR</dispatcher>
		<dispatcher>ASYNC</dispatcher>
	</filter-mapping>

3. Creating DAO

DAO : Data Access Object

3.1. Create TeacherDao classes

"Conversion" between t_teachers tables and Teacher classes

  • Converting a record operation to an object operation

  • Converting an operation of an object to an operation of a record

4, stratification

  • view layer
	HTML ,CSS ,JavaScript
	JSP ,Velocity
  • Control layer
	Servlet ,Struts ,Spring MVC
  • Business layer (service)

  • Data access layer (dao)

	JDBC , MyBatis ,Hibernate ,OpenJPA

Topics: encoding Java Database MySQL