<form action="" method="post">
<input type="text" name="num1">
<input type="text" name="num2">
<input type="submit" name="提交">
</form>
action 代码
HttpServletRequest request=ServletActionContext.getRequest()
int num1 =Intger.parInt(request.getParameter("num1"))
int num2 =Intger.parInt(request.getParameter("num2"))
int sum=num1+num2
request.setAttribute(sum,"sum")
jsp 代码
结果是:${sum}
毕业论文选题系统是基于微信小程序,后端是基于java编程语言,ssm框架,mysql数据库和IDEA工具开发,本系统分为学生,教师,管理员三个角色;学生可以注册登陆系统,查看系统公告,选课论文课题,提交课题论文,查看论文审核,答辩结果等信息;教师可以发布课题,审核学生论文,课题答辩结果,在线回复学生留言;管理员对学生,教师,公告,论文,选题,答辩等进行管理;本系统功能齐全,文档齐全,适合作为微信小程序毕业设计来参考和学习。一.技术环境
jdk版本:1.8 及以上
ide工具:IDEA ,微信小程序开发工具
数据库: mysql5.7 (必须5.7)
编程语言: Java
tomcat: 8.0 及以上
java框架:SSM
maven: 3.6.1
前端:layui ,微信
详细技术:HTML+CSS+JS+JSP+JAVA+SSM+MYSQL+JQUERY+MAVEN+微信开发工具
二.项目文件(项目获取请看文末官网)
在这里插入图片描述
三.系统功能
在这里插入图片描述
四.代码示例
package com.lmu.controller
/**
* 和登陆有关的都在这里
*/
import com.opensymphony.xwork2.ActionContext
import com.opensymphony.xwork2.ActionSupport
import com.lmu.model.Role
import com.lmu.model.User
import com.lmu.service.RoleService
import com.lmu.service.UserService
import com.lmu.utils.JsonUtils
import com.lmu.utils.UserUtils
import org.apache.commons.collections.map.HashedMap
import org.apache.struts2.ServletActionContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Controller
import java.io.IOException
import java.util.HashMap
import java.util.Map
@Controller("loginController")
@Scope("prototype")
public class LoginController extends ActionSupport {
@Autowired
private UserService userService
@Autowired
private RoleService roleService
private User user
private Map<String, Object>map = new HashMap()
public User getUser() {
return user
}
public void setUser(User user) {
this.user = user
}
public UserService getUserService() {
return userService
}
public void setUserService(UserService userService) {
this.userService = userService
}
/**
* 用户登陆
* @return
*/
public void index() throws IOException {
User user1 = userService.getUser(user)
if (user1 != null){
if (user1.getIsSh() == 1){
if (user1.getRole().getEnName().equals("admin")){
ActionContext.getContext().getSession().put("user", user1)
}
if (user1.getRole().getEnName().equals("js")){
ActionContext.getContext().getSession().put("user1", user1)
}
if (user1.getRole().getEnName().equals("xs")){
ActionContext.getContext().getSession().put("user2", user1)
}
map.put("flag", 1)
map.put("url", "login_indexs.do")
map.put("id", user1.getId())
JsonUtils.toJson(map)
} else {
map.put("flag", 2)
JsonUtils.toJson(map)
}
} else {
map.put("flag", 3)
JsonUtils.toJson(map)
}
}
public String indexs() throws IOException {
User u = UserUtils.getUser()
if (u != null){
ActionContext.getContext().put("user", u)
String ss = u.getRole().getEnName()
ActionContext.getContext().put("role", u.getRole().getEnName())
}
return SUCCESS
}
//登陆页面
public String login() {
return SUCCESS
}
//退出
public String tuichu() {
ActionContext ac = ActionContext.getContext()
Map session = ac.getSession()
session.remove("userName")
session.remove("userId")
ServletActionContext.getRequest().getSession().invalidate()
return "login"
}
}
package com.lmu.controller
/**
* 用户新增
*/
import com.opensymphony.xwork2.ActionContext
import com.opensymphony.xwork2.ActionSupport
import com.opensymphony.xwork2.ModelDriven
import com.lmu.model.Role
import com.lmu.model.User
import com.lmu.service.RoleService
import com.lmu.service.UserService
import com.lmu.utils.JsonUtils
import com.lmu.utils.Pager
import com.lmu.utils.UserUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Controller
import java.awt.event.FocusEvent
import java.io.IOException
import java.util.Date
import java.util.HashMap
import java.util.Map
@Controller("userController")
@Scope("prototype")
public class UserController extends ActionSupport implements ModelDriven<User>{
@Autowired
private UserService userService
@Autowired
private RoleService roleService
private User user
private Integer userId
private Map<String, Object>map = new HashMap()
/**
* list
*
* @return
*/
public String list() throws IOException {
User user1 = UserUtils.getUser()
if (user1 == null || user1.getId() == null){
ActionContext.getContext().put("login", 1)
return SUCCESS
}
Pager<User>pagers = null
Role role = user1.getRole()
if (role.getEnName().equals("admin")) {
pagers = userService.getList(user)
ActionContext.getContext().put("pagers", pagers)
ActionContext.getContext().put("user", user1)
ActionContext.getContext().put("role", role)
ActionContext.getContext().put("bean", user)
return SUCCESS
} else if (role.getEnName().equals("xs") || role.getEnName().equals("js")) {
pagers = userService.getList(user1)
ActionContext.getContext().put("pagers", pagers)
ActionContext.getContext().put("bean", user)
return SUCCESS
}
return null
}
/**
* 跳转add
*
* @return
*/
public String add() {
Pager<Role>pagers = roleService.pagers()
ActionContext.getContext().put("pagers", pagers)
return SUCCESS
}
/**
* 查询修改
*
* @return
*/
public String edit() {
User bean = userService.findById(userId)
Pager<Role>pagers = roleService.pagers()
ActionContext.getContext().put("bean", bean)
ActionContext.getContext().put("pagers", pagers)
return SUCCESS
}
/**
* 审核
*
* @return
*/
public void updateSh() throws IOException {
user.setIsSh(1)
userService.updates(user)
map.put("flag", true)
map.put("url", "user_list.do")
JsonUtils.toJson(map)
}
/**
* 更新
*
* @return
*/
public String update() throws IOException {
if (user.getPass().equals("")){
user.setPass(null)
}
userService.updates(user)
map.put("flag", true)
map.put("url", "user_list.do")
JsonUtils.toJson(map)
return SUCCESS
}
/**
* 保存
*
* @return
*/
public void save() throws IOException {
if (userService.getUser(user) != null){
map.put("flag", false)
map.put("url", "login_login.do")
JsonUtils.toJson(map)
} else {
user.setTime(new Date())
userService.save(user)
map.put("flag", true)
map.put("url", "login_login.do")
JsonUtils.toJson(map)
}
}
public void delete() throws IOException {
User user1 = userService.findById(userId)
user1.setIsDelete(1)
userService.update(user1)
map.put("flag", true)
map.put("url", "user_list.do")
JsonUtils.toJson(map)
}
@Override
public User getModel() {
if (user == null) {
user = new User()
}
return user
}
public Integer getUserId() {
return userId
}
public void setUserId(Integer userId) {
this.userId = userId
}
public User getUser() {
return user
}
public void setUser(User user) {
this.user = user
}
}
一、实现思路1.获取省份的列表值,有2种方式:一是返回List集合,在页面进行迭代;二是在业务类中将下拉列表封装好,页面通过JQuery方法写入。
这里暂时采用第二种方法。
2.前台JQuery:①数据库里面需要存的值,三者都有可能,三选一(判断是否选中了下面的级联项,按选中的最低级项为准值);
②将三个下拉框的name属性设置为变量,便于动态设置;③当修改重定位时,因为数据库中只有一个地区编号,所以需要根据地区编号将所在地区给定位。
定位方法:通过判断所在地区的编号后面的零,如果是四个0结束即为省,二个0即为市,都符合为区县。
3.调用方法:①jsp页面上引用include/js/cascadeCity.js;②调用返回省列表的方法provinceOption( *** 作类型, 省份编号, 城市编号, 区县编号)
③修改实体类(该实体类即你要修改的那个实体类),在实体类中添加private String provinceNumprivate String cityNumprivate String countyNum
及对应的get、set方法(添加实体类中变量可自定义),添加的这3个变量主要用于修改时定位用户已选城市地区。
二、实现
1.cascadeCity.js
/*
* subType - *** 作类型
* pNum - 省份编号
* cityNum - 城市编号
* countyNum - 区县编号
*
*/
function provinceOption(subType, pNum, cityNum, countyNum) {
$.ajax({
type: "POST",
url: "jsonCityAction!provincesInfo.action",
dataType:"text",
success: function(json){
var obj = $.parseJSON(json)
$("#province").html('<option value="" selected>\u8BF7\u9009\u62E9</option>' + obj.gS_Result)
if(subType == "modify") {
//给省份进行下拉框定位
$('#province option[value=' + pNum + ']').attr('selected', 'selected')
}
getCity(subType, pNum, cityNum, countyNum)
},
error: function(json){
alert("json=" + json)
return false
}
})
}
//改变省份时触发
function changeProvince() {
//当 *** 作id为province的下拉框时,触发事件
$("#province").change(function() {
var province_value = $("select[id='province'][@selected]").val()
getCity(operateType, province_value)
})
}
function getparmscity(){
var province_value = $("select[id='province'][@selected]").val()
getCity(operateType, province_value)
}
//改变城市时触发
function changeCity() {
//当 *** 作id为city的下拉框时,触发事件
$("#city").change(function() {
var city_value = $("select[id='city'][@selected]").val()
getCounty(operateType, city_value)
})
}
//返回城市列表
function getCity(subType, pNum, cityNum, countyNum) {
$.ajax({
type: "POST",
url: "jsonCityAction!cityInfo.action?gS_PNum=" + pNum,
dataType:"text",
success: function(json){
var obj = $.parseJSON(json)
$("#city").html('<option value="" selected>\u8BF7\u9009\u62E9</option>' + obj.gS_Result)
if(subType == "modify") {
//给城市定位
$('#city option[value="' + cityNum + '"]').attr('selected',true)
}
getCounty(subType, cityNum, countyNum)
},
error: function(json){
alert("json=" + json)
return false
}
})
}
//返回区县列表
function getCounty(subType, cityNum, countyNum) {
$.ajax({
type: "POST",
url: "jsonCityAction!countiesInfo.action?gS_CityNum=" + cityNum,
dataType:"text",
success: function(json){
var obj = $.parseJSON(json)
$("#county").html('<option value="" selected>\u8BF7\u9009\u62E9</option>' + obj.gS_Result)
if(subType == "modify") {
//给区县定位
$('#county option[value="' + countyNum + '"]').attr('selected',true)
}
},
error: function(json){
alert("json=" + json)
return false
}
})
}
2.jsp页面:
……
引入js
<script src="include/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="include/js/cascadeCity.js"></script>
<script type="text/javascript">
$(function() {
/***===级联城市使用===***/
changetrcompany()
changeProvince() //改变省份选项时触发事件
changeCity() //改变城市选项时触发事件
})
</script>
…………
<tr>
<td height="22" class=topline align="right">所属地区:</td>
<td bgcolor="#FFFFFF" height="22">
<div>
<div id="provinceDiv" class="divBL">
<select size='1' name="provinceName" id='province' class="sel"></select></div>
<div id="cityDiv" class="divBL">
<select size='1' id='city' class="sel"></select>
</div>
<div id="countyDiv" class="divBL">
<select size='1' id='county' class="sel"></select>
</div>
</div>
</td>
</tr>
3.struts.xml
<package name="ajaxSYS" extends="json-default" >
<action name="jsonCityAction" class="iCityAction">
<result type="json"/>
</package>
</action>
4.action类
import javax.annotation.Resource
import org.springframework.stereotype.Component
import com.ideamov.service.city.CityService
import com.opensymphony.xwork2.ActionSupport
@Component(value = "iCityAction")
public class CityAction extends ActionSupport {
private static final long serialVersionUID = -3234677100675620024L
private CityService iCityService
private String gS_PNum //省份编号
private String gS_CityNum //城市编号
private String gS_Result //返回数据
public String provincesInfo() throws Exception {
gS_Result = iCityService.getProvincesInfo()
return SUCCESS
}
public String cityInfo() throws Exception {
gS_Result = iCityService.getCityInfo(gS_PNum)
return SUCCESS
}
public String countiesInfo() throws Exception {
gS_Result = iCityService.getCountiesInfo(gS_CityNum)
return SUCCESS
}
/***=====set、get=====***/
public String getgS_Result() {
return gS_Result
}
public String getgS_PNum() {
return gS_PNum
}
public void setgS_PNum(String gSPNum) {
gS_PNum = gSPNum
}
public String getGS_CityNum() {
return gS_CityNum
}
public void setGS_CityNum(String cityNum) {
gS_CityNum = cityNum
}
@Resource
public void setCityService(CityService iCityService) {
this.iCityService = iCityService
}
}
5.业务层和dao层就是配合来完成数据库查询
/**
*
* 方法名: getProvincesInfo
* 方法描述: 获取省份的列表值
* 参数: @return
* 返回值:
* 异常:
*
*/
@Override
public String getProvincesInfo() {
StringBuffer sb_Provinces = new StringBuffer()
List<TcPublicProvinces>tcPPList = iTcPPDao.findAll(TcPublicProvinces.class, "orderNum", true, new Criterion[]{Restrictions.isNotNull("num")})
for(TcPublicProvinces tcPP : tcPPList) {
sb_Provinces.append("<option value='" + tcPP.getNum() + "'>" + tcPP.getTitle() + "</option>")
}
return sb_Provinces.toString()
}
/**
*
* 方法名: getCityInfo
* 方法描述: 通过省份编号,获取到城市列表
* 参数: @param pNum - 省份编号
* 参数: @return
* 返回值:
* 异常:
*
*/
@Override
public String getCityInfo(String pNum) {
StringBuffer sb_City = new StringBuffer()
List<TcPublicCity>tcPCList = iTcPCDao.findAll(TcPublicCity.class, "orderNum", true, new Criterion[]{Restrictions.eq("remark", pNum)})
for(TcPublicCity tcPC : tcPCList) {
sb_City.append("<option value='" + tcPC.getNum() + "'>" + tcPC.getTitle() + "</option>")
}
return sb_City.toString()
}
/**
*
* 方法名: getCountyInfo
* 方法描述: 根据城市编号,获取到区县列表的值
* 参数: @param cityNum - 城市编号
* 参数: @return
* 返回值:
* 异常:
*
*/
@Override
public String getCountiesInfo(String cityNum) {
StringBuffer sb_Countys = new StringBuffer()
List<TcPublicCounties>tcPCsList = iTcPCsDao.findAll(TcPublicCounties.class, "orderNum", true, new Criterion[]{Restrictions.eq("remark", cityNum)})
for(TcPublicCounties tcPCs : tcPCsList) {
sb_Countys.append("<option value='" + tcPCs.getNum() + "'>" + tcPCs.getTitle() + "</option>")
}
return sb_Countys.toString()
}
PS:有问题可留蔻蔻,我加你!~good luck!~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)