update
add new function: student info query
This commit is contained in:
parent
cd22446aaa
commit
1f73a30965
@ -39,12 +39,25 @@
|
||||
</bean>
|
||||
<!-- 配置静态资源处理器 -->
|
||||
<mvc:resources mapping="/resources/**" location="/resources/"/>
|
||||
<mvc:view-controller path="/" view-name="login" />
|
||||
<mvc:view-controller path="/" view-name="login"/>
|
||||
|
||||
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
|
||||
<constructor-arg index="0" ref="sqlSessionFactory" />
|
||||
<constructor-arg index="0" ref="sqlSessionFactory"/>
|
||||
</bean>
|
||||
|
||||
<!-- <bean id="characterEncodingFilter" class="org.springframework.boot.web.servlet.FilterRegistrationBean">-->
|
||||
<!-- <property name="filter">-->
|
||||
<!-- <bean class="org.springframework.web.filter.CharacterEncodingFilter">-->
|
||||
<!-- <property name="encoding" value="UTF-8"/>-->
|
||||
<!-- <property name="forceEncoding" value="true"/>-->
|
||||
<!-- </bean>-->
|
||||
<!-- </property>-->
|
||||
<!-- <property name="urlPatterns">-->
|
||||
<!-- <list>-->
|
||||
<!-- <value>/*</value>-->
|
||||
<!-- </list>-->
|
||||
<!-- </property>-->
|
||||
<!-- </bean>-->
|
||||
|
||||
</beans>
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -7,30 +7,34 @@
|
||||
SELECT * FROM student
|
||||
</select>
|
||||
|
||||
<select id="getQueryStudents" resultType="cyou.chenx221.pojo.Student">
|
||||
<select id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
|
||||
SELECT * FROM student
|
||||
WHERE
|
||||
WHERE 1=1
|
||||
<if test="name != null and name != ''">
|
||||
name = #{name}
|
||||
AND name = #{name}
|
||||
</if>
|
||||
<if test="sex != null and sex != ''">
|
||||
AND sex = #{sex}
|
||||
</if>
|
||||
<if test="birthday != null">
|
||||
AND birthday = #{birthday}
|
||||
</if>
|
||||
<if test="option != null and option != ''">
|
||||
AND sex = #{option}
|
||||
# option = "男" or "女"
|
||||
</if>
|
||||
<if test="id != 0">
|
||||
AND id = #{id}
|
||||
</if>
|
||||
<if test="phone != null and phone != ''">
|
||||
AND phone = #{phone}
|
||||
</if>
|
||||
<if test="classes != null and classes.size() > 0">
|
||||
<if test="id != -1">
|
||||
AND id = #{id}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getQueryStudents2" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
|
||||
SELECT * FROM student
|
||||
WHERE 1=1
|
||||
<if test="classess != null and classess.size() > 0">
|
||||
AND classes IN
|
||||
<foreach item="item" index="index" collection="classes" open="(" separator="," close=")">
|
||||
#{item}
|
||||
<foreach item="className" collection="classess" open="(" separator="," close=")">
|
||||
#{className}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -16,4 +16,21 @@
|
||||
<servlet-name>dispatcherServlet</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
@ -82,13 +82,6 @@
|
||||
<version>8.0.28</version>
|
||||
</dependency>
|
||||
|
||||
<!-- log4j -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.20.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
@ -97,7 +90,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<version>4.13.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -124,7 +117,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.2</version>
|
||||
<version>2.12.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
@ -146,7 +139,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.10.0</version>
|
||||
<version>2.12.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -2,6 +2,7 @@ package cyou.chenx221.controller;
|
||||
|
||||
import cyou.chenx221.pojo.Student;
|
||||
import cyou.chenx221.service.StudentService;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -12,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -37,19 +40,41 @@ public class StudentController {
|
||||
return "studentListQuery"; // 重定向到 dashboard 页面
|
||||
}
|
||||
|
||||
@PostMapping(value = "/query",produces = "application/x-www-form-urlencoded;charset=UTF-8")
|
||||
public String getQueryStudents(@RequestParam(value = "name", required = true) String name,
|
||||
@RequestParam(value = "birthday", required = false) Date birthday,
|
||||
@RequestParam(value = "inlineRadioOptions", required = false) String option,
|
||||
@RequestParam(value = "student-id", required = false) int id,
|
||||
@RequestParam(value = "phone", required = false) String phone,
|
||||
@RequestParam(value = "class", required = false) List<String> classes,
|
||||
@PostMapping(value = "/query", produces = "application/x-www-form-urlencoded;charset=UTF-8")
|
||||
public String getQueryStudents(@RequestParam(value = "name", defaultValue = "null", required = false) String name,
|
||||
@RequestParam(value = "birthday", defaultValue = "#{null}", required = false) Date birthday,
|
||||
@RequestParam(value = "inlineRadioOptions", defaultValue = "null", required = false) String option,
|
||||
@RequestParam(value = "student-id", defaultValue = "-1", required = false) int id,
|
||||
@RequestParam(value = "phone", defaultValue = "null", required = false) String phone,
|
||||
@RequestParam(value = "classes", defaultValue = "", required = false) List<String> classes,
|
||||
Model model) {
|
||||
System.out.println("name:" + name + " birthday:" + birthday + " option:" + option + " id:" + id + " phone:" + phone);//debug
|
||||
// List<Student> students = studentService.getQueryStudents(name, birthday, option, id, phone, classes);
|
||||
// model.addAttribute("students", students);
|
||||
// return "studenQueryResult"; // 重定向到 dashboard 页面
|
||||
return "success";
|
||||
//根据classes是否为空,判断是否需要查询班级,如果为空则不需要查询班级,如果不为空则仅查询班级
|
||||
//debug
|
||||
System.out.println("name: " + name);
|
||||
System.out.println("birthday: " + birthday);
|
||||
System.out.println("option: " + option);
|
||||
System.out.println("id: " + id);
|
||||
System.out.println("phone: " + phone);
|
||||
System.out.println("classes: " + classes);
|
||||
|
||||
List<Student> students;
|
||||
Student student;
|
||||
if (classes.size() == 0) {
|
||||
if (name.equals("null")) name = null;
|
||||
if (option.equals("null")) option = null;
|
||||
if (phone.equals("null")) phone = null;
|
||||
student = new Student(id, name, option, birthday, phone);
|
||||
students = studentService.getQueryStudents(student);
|
||||
} else {
|
||||
if (classes.size() == 1 && classes.get(0).equals("")) classes = null;
|
||||
student = new Student(classes);
|
||||
students = studentService.getQueryStudents2(student);
|
||||
}
|
||||
|
||||
|
||||
model.addAttribute("students", students);
|
||||
return "studentQueryResult"; // 重定向到 dashboard 页面
|
||||
// return "success";
|
||||
}
|
||||
|
||||
// // 示例:处理查询学生信息的请求
|
||||
|
@ -14,5 +14,6 @@ public interface StudentDao {
|
||||
Student getStudentById(int studentId);
|
||||
List<Student> getAllStudents();
|
||||
|
||||
List<Student> getQueryStudents(String name, Date birthday, String option, int id, String phone, List<String> classes);
|
||||
List<Student> getQueryStudents(Student student);
|
||||
List<Student> getQueryStudents2(Student student);
|
||||
}
|
||||
|
@ -47,15 +47,11 @@ public class StudentDaoImpl implements StudentDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Student> getQueryStudents(String name, Date birthday, String option, int id, String phone, List<String> classes) {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("name", name);
|
||||
parameters.put("birthday", birthday);
|
||||
parameters.put("option", option);
|
||||
parameters.put("id", id);
|
||||
parameters.put("phone", phone);
|
||||
parameters.put("classes", classes);
|
||||
|
||||
return sqlSession.selectList("cyou.chenx221.mapper.StudentDao.getQueryStudents", parameters);
|
||||
public List<Student> getQueryStudents(Student student) {
|
||||
return sqlSession.selectList("cyou.chenx221.mapper.StudentDao.getQueryStudents", student);
|
||||
}
|
||||
@Override
|
||||
public List<Student> getQueryStudents2(Student student){
|
||||
return sqlSession.selectList("cyou.chenx221.mapper.StudentDao.getQueryStudents2", student);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Student {
|
||||
private Integer id;
|
||||
@ -14,8 +15,15 @@ public class Student {
|
||||
private Date birthday;
|
||||
private String phone;
|
||||
private String classes;
|
||||
private List<String> classess;
|
||||
|
||||
public List<String> getClassess() {
|
||||
return classess;
|
||||
}
|
||||
|
||||
public void setClassess(List<String> classess) {
|
||||
this.classess = classess;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
@ -57,6 +65,9 @@ public class Student {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public Student(List<String> classess) {
|
||||
this.classess = classess;
|
||||
}
|
||||
|
||||
public Student(Integer id, String name, String sex, Date birthday, String phone, String classes) {
|
||||
this.id = id;
|
||||
@ -67,6 +78,14 @@ public class Student {
|
||||
this.classes = classes;
|
||||
}
|
||||
|
||||
public Student(Integer id, String name, String sex, Date birthday, String phone) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.sex = sex;
|
||||
this.birthday = birthday;
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public Student() {
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,11 @@ public class StudentService {
|
||||
return studentDao.getAllStudents();
|
||||
}
|
||||
|
||||
public List<Student> getQueryStudents(String name, Date birthday, String option, int id, String phone, List<String> classes) {
|
||||
return studentDao.getQueryStudents(name,birthday,option,id,phone,classes);
|
||||
public List<Student> getQueryStudents(Student student) {
|
||||
return studentDao.getQueryStudents(student);
|
||||
}
|
||||
|
||||
public List<Student> getQueryStudents2(Student student) {
|
||||
return studentDao.getQueryStudents2(student);
|
||||
}
|
||||
}
|
||||
|
@ -39,12 +39,25 @@
|
||||
</bean>
|
||||
<!-- 配置静态资源处理器 -->
|
||||
<mvc:resources mapping="/resources/**" location="/resources/"/>
|
||||
<mvc:view-controller path="/" view-name="login" />
|
||||
<mvc:view-controller path="/" view-name="login"/>
|
||||
|
||||
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
|
||||
<constructor-arg index="0" ref="sqlSessionFactory" />
|
||||
<constructor-arg index="0" ref="sqlSessionFactory"/>
|
||||
</bean>
|
||||
|
||||
<!-- <bean id="characterEncodingFilter" class="org.springframework.boot.web.servlet.FilterRegistrationBean">-->
|
||||
<!-- <property name="filter">-->
|
||||
<!-- <bean class="org.springframework.web.filter.CharacterEncodingFilter">-->
|
||||
<!-- <property name="encoding" value="UTF-8"/>-->
|
||||
<!-- <property name="forceEncoding" value="true"/>-->
|
||||
<!-- </bean>-->
|
||||
<!-- </property>-->
|
||||
<!-- <property name="urlPatterns">-->
|
||||
<!-- <list>-->
|
||||
<!-- <value>/*</value>-->
|
||||
<!-- </list>-->
|
||||
<!-- </property>-->
|
||||
<!-- </bean>-->
|
||||
|
||||
</beans>
|
||||
|
@ -7,30 +7,34 @@
|
||||
SELECT * FROM student
|
||||
</select>
|
||||
|
||||
<select id="getQueryStudents" resultType="cyou.chenx221.pojo.Student">
|
||||
<select id="getQueryStudents" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
|
||||
SELECT * FROM student
|
||||
WHERE
|
||||
WHERE 1=1
|
||||
<if test="name != null and name != ''">
|
||||
name = #{name}
|
||||
AND name = #{name}
|
||||
</if>
|
||||
<if test="sex != null and sex != ''">
|
||||
AND sex = #{sex}
|
||||
</if>
|
||||
<if test="birthday != null">
|
||||
AND birthday = #{birthday}
|
||||
</if>
|
||||
<if test="option != null and option != ''">
|
||||
AND sex = #{option}
|
||||
# option = "男" or "女"
|
||||
</if>
|
||||
<if test="id != 0">
|
||||
AND id = #{id}
|
||||
</if>
|
||||
<if test="phone != null and phone != ''">
|
||||
AND phone = #{phone}
|
||||
</if>
|
||||
<if test="classes != null and classes.size() > 0">
|
||||
<if test="id != -1">
|
||||
AND id = #{id}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getQueryStudents2" parameterType="cyou.chenx221.pojo.Student" resultType="cyou.chenx221.pojo.Student">
|
||||
SELECT * FROM student
|
||||
WHERE 1=1
|
||||
<if test="classess != null and classess.size() > 0">
|
||||
AND classes IN
|
||||
<foreach item="item" index="index" collection="classes" open="(" separator="," close=")">
|
||||
#{item}
|
||||
<foreach item="className" collection="classess" open="(" separator="," close=")">
|
||||
#{className}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -16,4 +16,21 @@
|
||||
<servlet-name>dispatcherServlet</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
Reference in New Issue
Block a user