-DarchetypeCatalog=internal
javax.servlet
javax.servlet-api
3.1.0
provided
org.springframework
spring-context
4.3.19.RELEASE
org.springframework
spring-web
4.3.19.RELEASE
org.springframework
spring-webmvc
4.3.19.RELEASE
org.mybatis
mybatis
3.4.6
org.mybatis
mybatis-spring
1.3.1
org.springframework
spring-jdbc
4.3.19.RELEASE
mysql
mysql-connector-java
8.0.11
org.aspectj
aspectjweaver
1.8.13
在IntelliJ IDEA中需要指定资源位置,所以还需要在pom.xml文件中加入以下配置:
src/main/java
**/*.xml
src/main/resources
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
CharacterEncodingFilter
/*
contextConfigLocation
classpath:spring.xml
dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
1
dispatcher
*.ajax
*.do
org.springframework.web.context.ContextLoaderListener
login.jsp
Archetype Created Web Application
本次设计使用的数据库是MySQL。
CREATE TABLE `linakge` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`province` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`city` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`district` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`other` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
本次实现省市县三级联动是使用jQuery插件,插件下载地址为:
jQuery省市县三级联动插件
package bmg.linakge.model;
public class Linakge {
private int id;
private String province;
private String city;
private String district;
private String other;
public int getId() {
return id;
}
public String getProvince() {
return province;
}
public String getCity() {
return city;
}
public String getDistrict() {
return district;
}
public String getOther() {
return other;
}
public void setId(int id) {
this.id = id;
}
public void setProvince(String province) {
this.province = province;
}
public void setCity(String city) {
this.city = city;
}
public void setDistrict(String district) {
this.district = district;
}
public void setOther(String other) {
this.other = other;
}
}
package bmg.linakge.controller;
import bmg.linakge.model.Linakge;
import bmg.linakge.service.LinakgeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("linakgeController")
public class LinakgeController {
@Resource
private LinakgeService linakgeService;
@RequestMapping("addLinakge.do")
public String addLinakge(Linakge linakge, HttpServletRequest request){
String province = request.getParameter("province10");
String city = request.getParameter("city10");
String district = request.getParameter("district10");
String other = request.getParameter("other");
linakge.setProvince(province);
linakge.setCity(city);
linakge.setDistrict(district);
linakge.setOther(other);
int i =linakgeService.addLinakge(linakge);
return "aa.jsp";
}
}
package bmg.linakge.service;
import bmg.linakge.model.Linakge;
public interface LinakgeService {
int addLinakge(Linakge linakge);
}
package bmg.linakge.service.impl;
import bmg.linakge.mapper.LinakgeMapper;
import bmg.linakge.model.Linakge;
import bmg.linakge.service.LinakgeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class LinakgeServiceImpl implements LinakgeService {
@Resource
private LinakgeMapper linakgeMapper;
@Override
public int addLinakge(Linakge linakge) {
return linakgeMapper.addLinakge(linakge);
}
}
package bmg.linakge.mapper;
import bmg.linakge.model.Linakge;
public interface LinakgeMapper {
int addLinakge(Linakge linakge);
}
insert into linakge
province,
city,
district,
other,
#{province},
#{city},
#{district},
#{other},